出神入化的分块 Educational Codeforces Round 71 (Rated for Div. 2) E Remainder Problem

Educational Codeforces Round 71 (Rated for Div. 2) E Remainder Problem
题意: 两种操作,一种$a_x+y$,第二种查询

所有模$x$等于$y$位置的和.
题解: $\%x=y$ 这不就是分块么,就是分块的性质啊,直接处理不就OK了??,想什么线段树。真6.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#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;
}