Codeforces Round #701 (Div. 2)
作者:互联网
Codeforces Round #701 (Div. 2)之心态爆炸
B - Replace and Keep Sorted
题意:
思路:因为都是前一个和后一个有关系,就得先记录贡献才行,没考虑到问的\(l = r\),被×祭。
代码:
#include <iostream>
using namespace std;
typedef long long ll;
const ll maxn = 1e9 + 7;
const double eps = 1e-6;
const ll N = 1e5 + 999;
ll a[N];
ll sum[N];
void solve() {
ll n, q, k;cin >> n >> q >> k;
for (ll i = 1; i <= n; i++)
cin >> a[i];
for (ll i = 2; i < n; i++) {
sum[i] = sum[i-1] - a[i-1] - 1 + a[i + 1] - 1;
}
while (q--) {
ll l, r;cin >> l >> r;
ll ans = sum[r-1] - sum[l];
if (r == l)ans = k-1;
else
ans += -1 + a[l + 1]-1 + k -a[r-1]-1;
cout << ans << endl;
}
}
signed main() {
ll t = 1;//cin >> t;
while (t--)
solve();
}
D - Multiples and Power Differences
题意:
思路:猜到了是一列对角线是\(lcm(1, 2, 3, \cdots , 16)-x^4\),一列是\(lcm(1, 2, 3, \cdots , 16)\),然后因为循环时吧\(k\)写成\(i\)当场身亡。
代码:
#include <iostream>
using namespace std;
typedef long long ll;
const ll maxn = 1e9 + 7;
const double eps = 1e-6;
const ll N = 700;
ll a[N][N];
ll b[N][N];
ll f[167];
const ll NN = 720720;
void solve() {
ll n, m;cin >> n >> m;
for (ll i = 1; i <= n; i++) {
for (ll j = 1; j <= m; j++) {
cin >> a[i][j];
}
}
for (ll i = 1;i <= n; i++) {
for (ll j = 1; j <= m; j++) {
if ((i + j) % 2 == 1) {
b[i][j] = NN;
}else {
for (ll k = 1; k <= 16; k++) {//k能写成i我是没想到的
ll x = (k * k * k * k);
if ( (NN-x) % a[i][j] == 0 && NN-x > 0) {
b[i][j] = NN-x;
break;
}
}
}
cout << b[i][j] << " ";
}
cout << endl;
}
}
signed main() {
ll t = 1;//cin >> t;
while (t--)
solve();
}
总结:
1. 注意在前缀和时,用到了类似前缀和的数组,要判断询问是否\(l = r\),很重要。
2. 注意在写代码时,不要用重复的变量名字。
标签:const,cin,sum,701,long,Codeforces,solve,Div,ll 来源: https://www.cnblogs.com/Xiao-yan/p/14399688.html