牛客春招刷题训练营-2025.4.17题解
活动地址: 牛客春招刷题训练营 - 编程打卡活动
简单题 彩虹糖的梦
直接输出 个数中的最小值。
print(min(list(map(int,input().split()))))
中等题 彩虹糖的梦
符号解释: 表示
能整除
。
轴上能到达的位置满足
。
轴上能到达的位置满足
。
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
int x, y, a, b, c, d;
cin >> x >> y >> a >> b >> c >> d;
cout << (((y % gcd(a, b) == 0) && (x % gcd(c, d) == 0)) ? "YES\n" : "NO\n");
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int t = 1;
cin >> t;
while (t--)
solve();
return 0;
}
困难题 【模板】差分
与前缀和相反的思想。
我们开数组 ,如果
加上
,
减去
,对
做前缀和后相当于
内每个数都加上了
。
因此处理完每个区间加操作后只需最后做一遍前缀和即可得到原数组。
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
cin >> n >> q;
vector<ll> a(n + 1), cf(n + 2);
for (int i = 1; i <= n; i++)cin >> a[i];
while (q--) {
ll l, r, k;
cin >> l >> r >> k;
cf[l] += k;
cf[r + 1] -= k;
}
for (int i = 1; i <= n; i++) {
cf[i] += cf[i - 1];
cout << a[i] + cf[i] << ' ';
}
return 0;
}
#牛客春招刷题训练营#