Educational Codeforces Round 71 (Rated for Div. 2) E Remainder Problem
题意: 两种操作,一种
a
x
+
y
a_x+y
ax+y,第二种查询
∑
i
=
y
5
e
5
a
i
,
(
i
%
x
=
=
y
)
\sum_{i=y}^{5e5}a_i,(i\%x==y)
i=y∑5e5ai,(i%x==y)
所有模
x
x
x等于
y
y
y位置的和.
题解:
%
x
=
y
\%x=y
%x=y 这不就是分块么,就是分块的性质啊,直接处理不就OK了??,想什么线段树。真6.
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int, int> P;
#define VNAME(value) (#value)
#define bug printf("*********\n");
#define debug(x) cout<<"["<<VNAME(x)<<" = "<<x<<"]"<<endl;
#define mid ((l + r) >> 1)
#define chl 2 * k + 1
#define chr 2 * k + 2
#define lson l, mid, chl
#define rson mid + 1, r, chr
#define eb(x) emplace_back(x)
#define pb(x) emplace_back(x)
#define mem(a, b) memset(a, b, sizeof(a));
const LL mod = (LL) 1e9 + 7;
const int maxn = (int) 1e3 + 5;
const LL INF = 0x7fffffff;
const LL inf = 0x3f3f3f3f;
const double eps = 1e-8;
#ifndef ONLINE_JUDGE
clock_t prostart = clock();
#endif
void f() {
#ifndef ONLINE_JUDGE
freopen("../data.in", "r", stdin);
#endif
}
//typedef __int128 LLL;
template<typename T>
void read(T &w) {//读入
char c;
while (!isdigit(c = getchar()));
w = c & 15;
while (isdigit(c = getchar()))
w = w * 10 + (c & 15);
}
template<typename T>
void output(T x) {
if (x < 0)
putchar('-'), x = -x;
int ss[55], sp = 0;
do
ss[++sp] = x % 10;
while (x /= 10);
while (sp)
putchar(48 + ss[sp--]);
}
int n, m;
const int B = 1e3;
LL q[maxn][maxn];
LL a[maxn * 1000];
int main() {
f();
read(n);
while (n--) {
int op, x, y;
scanf("%d%d%d", &op, &x, &y);
if (op == 1) {
a[x] += y;
for (int i = 1; i <= B; i++) {
q[i][x % i] += y;
}
} else {
if (x <= B) {
printf("%lld\n", q[x][y]);
} else {
LL res = 0;
while (y <= 500000) {
res += a[y];
y += x;
}
printf("%lld\n", res);
}
}
}
#ifndef ONLINE_JUDGE
cout << "运行时间:" << 1.0 * (clock() - prostart) / CLOCKS_PER_SEC << endl;
#endif
return 0;
}