Submission #35597285
Source Code Expand
#include<iostream>
#include<vector>
using namespace std;
const int SIZE = 1 << 20;
const int len = 1 << 19;
int n, m, q;
int query[200010][4];
vector<pair<int, int>> v[200010];
long long tree[SIZE];
long long lazy[SIZE];
long long ans[200010];
int cnt;
void propagate(int idx)
{
if(idx < len)
{
lazy[2 * idx] += lazy[idx];
lazy[2 * idx + 1] += lazy[idx];
}
tree[idx] += lazy[idx];
lazy[idx] = 0;
}
void update(int idx, int s, int e, int ts, int te, long long v)
{
int mid;
propagate(idx);
if(s > te || e < ts) return;
else if(ts <= s && e <= te)
{
lazy[idx] = v;
propagate(idx);
return;
}
mid = (s + e) / 2;
update(2 * idx, s, mid, ts, te, v);
update(2 * idx + 1, mid + 1, e, ts, te, v);
}
long long get(int idx, int s, int e, int ts, int te)
{
int mid;
propagate(idx);
if(s > te || e < ts) return 0;
else if(ts <= s && e <= te) return tree[idx];
mid = (s + e) / 2;
return get(2 * idx, s, mid, ts, te) + get(2 * idx + 1, mid + 1, e, ts, te);
}
int main()
{
int i, j;
cin >> n >> m >> q;
for(i = 0; i < q; i++)
{
for(j = 0; j < 3; j++)
{
cin >> query[i][j];
}
if(query[i][0] == 1) cin >> query[i][3];
}
for(i = q - 1; i >= 0; i--)
{
if(query[i][0] == 1) update(1, 0, len - 1, query[i][1], query[i][2], query[i][3]);
else if(query[i][0] == 2)
{
for(j = 0; j < v[query[i][1]].size(); j++)
{
ans[v[query[i][1]][j].second] += query[i][2] + get(1, 0, len - 1, v[query[i][1]][j].first, v[query[i][1]][j].first);
}
v[query[i][1]].clear();
}
else
{
v[query[i][1]].push_back(make_pair(query[i][2], cnt));
ans[cnt] -= get(1, 0, len - 1, query[i][2], query[i][2]);
cnt++;
}
}
for(i = 1; i <= n; i++)
{
for(j = 0; j < v[i].size(); j++)
{
ans[v[i][j].second] += get(1, 0, len - 1, v[i][j].first, v[i][j].first);
}
}
for(i = cnt - 1; i >= 0; i--)
{
cout << ans[i] << '\n';
}
}
Submission Info
Submission Time |
|
Task |
F - Operations on a Matrix |
User |
gojib2002 |
Language |
C++ (Clang 10.0.0) |
Score |
500 |
Code Size |
2350 Byte |
Status |
AC |
Exec Time |
444 ms |
Memory |
19648 KiB |
Judge Result
Set Name |
Sample |
All |
Score / Max Score |
0 / 0 |
500 / 500 |
Status |
|
|
Set Name |
Test Cases |
Sample |
example_00.txt, example_01.txt, example_02.txt |
All |
example_00.txt, example_01.txt, example_02.txt, test_00.txt, test_01.txt, test_02.txt, test_03.txt, test_04.txt, test_05.txt, test_06.txt, test_07.txt, test_08.txt, test_09.txt, test_10.txt, test_11.txt, test_12.txt, test_13.txt, test_14.txt, test_15.txt, test_16.txt, test_17.txt, test_18.txt, test_19.txt, test_20.txt, test_21.txt, test_22.txt, test_23.txt, test_24.txt, test_25.txt, test_26.txt, test_27.txt, test_28.txt, test_29.txt, test_30.txt |
Case Name |
Status |
Exec Time |
Memory |
example_00.txt |
AC |
11 ms |
7908 KiB |
example_01.txt |
AC |
7 ms |
7804 KiB |
example_02.txt |
AC |
7 ms |
7896 KiB |
test_00.txt |
AC |
442 ms |
19588 KiB |
test_01.txt |
AC |
440 ms |
19464 KiB |
test_02.txt |
AC |
444 ms |
19580 KiB |
test_03.txt |
AC |
441 ms |
19576 KiB |
test_04.txt |
AC |
443 ms |
19648 KiB |
test_05.txt |
AC |
397 ms |
14004 KiB |
test_06.txt |
AC |
424 ms |
16468 KiB |
test_07.txt |
AC |
422 ms |
17824 KiB |
test_08.txt |
AC |
423 ms |
16568 KiB |
test_09.txt |
AC |
402 ms |
14308 KiB |
test_10.txt |
AC |
23 ms |
12736 KiB |
test_11.txt |
AC |
391 ms |
16404 KiB |
test_12.txt |
AC |
182 ms |
14700 KiB |
test_13.txt |
AC |
405 ms |
17712 KiB |
test_14.txt |
AC |
217 ms |
15964 KiB |
test_15.txt |
AC |
95 ms |
11848 KiB |
test_16.txt |
AC |
114 ms |
13596 KiB |
test_17.txt |
AC |
319 ms |
13148 KiB |
test_18.txt |
AC |
159 ms |
10192 KiB |
test_19.txt |
AC |
50 ms |
10764 KiB |
test_20.txt |
AC |
413 ms |
17896 KiB |
test_21.txt |
AC |
412 ms |
17924 KiB |
test_22.txt |
AC |
411 ms |
17900 KiB |
test_23.txt |
AC |
412 ms |
18016 KiB |
test_24.txt |
AC |
410 ms |
17904 KiB |
test_25.txt |
AC |
415 ms |
18040 KiB |
test_26.txt |
AC |
413 ms |
17972 KiB |
test_27.txt |
AC |
417 ms |
17884 KiB |
test_28.txt |
AC |
414 ms |
17984 KiB |
test_29.txt |
AC |
414 ms |
18040 KiB |
test_30.txt |
AC |
416 ms |
11148 KiB |