# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
201028 |
2020-02-09T06:26:33 Z |
gs14004 |
Fire (JOI20_ho_t5) |
C++17 |
|
473 ms |
47840 KB |
#include <bits/stdc++.h>
#define sz(v) ((int)(v).size())
#define all(v) (v).begin(), (v).end()
using namespace std;
using lint = long long;
using pi = pair<lint, lint>;
const int MAXN = 200005;
const int MAXT = 600050;
pi operator+(pi a, pi b){
return pi(a.first + b.first, a.second + b.second);
}
struct bit{
pi tree[MAXT];
void add(int x, pi v){
x += MAXN;
for(int i=x; i<MAXT; i+=i&-i) tree[i] = tree[i] + v;
}
pi query(int x){
x += MAXN;
pi ret(0, 0);
for(int i=x; i; i-=i&-i) ret = ret + tree[i];
return ret;
}
}bit1, bit2;
struct seg{
pi tree[MAXT];
int lim;
void init(int n, int *a){
for(lim = 1; lim <= n; lim <<= 1);
for(int i=1; i<=n; i++){
tree[i + lim] = pi(a[i], i);
}
for(int i=lim; i; i--) tree[i] = max(tree[2*i], tree[2*i+1]);
}
pi query(int s, int e){
s += lim;
e += lim;
pi ret(-1e9, 1e9);
while(s < e){
if(s%2 == 1) ret = max(ret, tree[s++]);
if(e%2 == 0) ret = max(ret, tree[e--]);
s >>= 1;
e >>= 1;
}
if(s == e) ret = max(ret, tree[s]);
return ret;
}
}seg;
struct ev1{ // y <= QUERY
int upd, pos, val;
bool operator<(const ev1 &e)const{
return upd < e.upd;
}
};
struct ev2{ // y - t <= QUERY
int upd, pos, val;
bool operator<(const ev2 &e)const{
return upd < e.upd;
}
};
vector<ev1> kek1;
vector<ev2> kek2;
void ADD(int x, int y, int v){
int t = y - x;
if(t > 1e7) return;
kek1.push_back({t, y, v});
kek2.push_back({t, x + 1, -v});
}
void solve(int s, int e){
if(s > e) return;
auto m = seg.query(s, e);
solve(s, m.second - 1);
solve(m.second + 1, e);
if(s == 1) s = -1e9;
int v = m.first;
int p = m.second;
ADD(p, p, v);
ADD(p, e + 1, -v);
ADD(s - 1, p, -v);
ADD(s - 1, e + 1, v);
}
struct query{
int t, r, idx, buho;
bool operator<(const query &q)const{
return t < q.t;
}
}qr[MAXN * 2];
int n, q, a[MAXN];
lint ret[MAXN];
int main(){
scanf("%d %d",&n,&q);
for(int i=1; i<=n; i++) scanf("%d",&a[i]);
seg.init(n, a);
solve(1, n);
for(int i=0; i<q; i++){
int t, l, r;
scanf("%d %d %d",&t,&l,&r);
qr[2 * i] = {t, r, i, +1};
qr[2 * i + 1] = {t, l-1, i, -1};
}
sort(qr, qr + q + q);
sort(all(kek1));
sort(all(kek2));
int ptr1 = 0;
int ptr2 = 0;
for(int i=0; i<q*2; i++){
while(ptr1 < sz(kek1) && kek1[ptr1].upd <= qr[i].t){
bit1.add(kek1[ptr1].pos, pi(kek1[ptr1].val, 1ll * kek1[ptr1].val * (1 - kek1[ptr1].pos)));
ptr1++;
}
while(ptr2 < sz(kek2) && kek2[ptr2].upd <= qr[i].t){
bit2.add(kek2[ptr2].pos, pi(kek2[ptr2].val, 1ll * kek2[ptr2].val * (1 - kek2[ptr2].pos)));
ptr2++;
}
lint sum = 0;
auto qr1 = bit1.query(qr[i].r);
sum += qr1.first * qr[i].r + qr1.second;
auto qr2 = bit2.query(qr[i].r - qr[i].t);
sum += qr2.first * (qr[i].r - qr[i].t) + qr2.second;
ret[qr[i].idx] += qr[i].buho * sum;
}
for(int i=0; i<q; i++) printf("%lld\n", ret[i]);
}
Compilation message
ho_t5.cpp: In function 'int main()':
ho_t5.cpp:102:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d",&n,&q);
~~~~~^~~~~~~~~~~~~~~
ho_t5.cpp:103:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1; i<=n; i++) scanf("%d",&a[i]);
~~~~~^~~~~~~~~~~~
ho_t5.cpp:108:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d",&t,&l,&r);
~~~~~^~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
9848 KB |
Output is correct |
2 |
Correct |
12 ms |
9848 KB |
Output is correct |
3 |
Correct |
12 ms |
9848 KB |
Output is correct |
4 |
Correct |
10 ms |
9900 KB |
Output is correct |
5 |
Correct |
12 ms |
9848 KB |
Output is correct |
6 |
Correct |
11 ms |
9824 KB |
Output is correct |
7 |
Correct |
10 ms |
9848 KB |
Output is correct |
8 |
Correct |
10 ms |
9852 KB |
Output is correct |
9 |
Correct |
12 ms |
9848 KB |
Output is correct |
10 |
Correct |
10 ms |
9848 KB |
Output is correct |
11 |
Correct |
12 ms |
9848 KB |
Output is correct |
12 |
Correct |
14 ms |
9848 KB |
Output is correct |
13 |
Correct |
14 ms |
9848 KB |
Output is correct |
14 |
Correct |
12 ms |
9848 KB |
Output is correct |
15 |
Correct |
12 ms |
9848 KB |
Output is correct |
16 |
Correct |
12 ms |
9848 KB |
Output is correct |
17 |
Correct |
11 ms |
9848 KB |
Output is correct |
18 |
Correct |
11 ms |
9876 KB |
Output is correct |
19 |
Correct |
11 ms |
9848 KB |
Output is correct |
20 |
Correct |
14 ms |
9880 KB |
Output is correct |
21 |
Correct |
14 ms |
9848 KB |
Output is correct |
22 |
Correct |
13 ms |
9848 KB |
Output is correct |
23 |
Correct |
11 ms |
9848 KB |
Output is correct |
24 |
Correct |
12 ms |
9896 KB |
Output is correct |
25 |
Correct |
11 ms |
9824 KB |
Output is correct |
26 |
Correct |
10 ms |
9848 KB |
Output is correct |
27 |
Correct |
25 ms |
9888 KB |
Output is correct |
28 |
Correct |
12 ms |
9848 KB |
Output is correct |
29 |
Correct |
11 ms |
9848 KB |
Output is correct |
30 |
Correct |
10 ms |
9848 KB |
Output is correct |
31 |
Correct |
10 ms |
9848 KB |
Output is correct |
32 |
Correct |
11 ms |
9840 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
9848 KB |
Output is correct |
2 |
Correct |
365 ms |
45836 KB |
Output is correct |
3 |
Correct |
364 ms |
45516 KB |
Output is correct |
4 |
Correct |
452 ms |
45960 KB |
Output is correct |
5 |
Correct |
402 ms |
46144 KB |
Output is correct |
6 |
Correct |
380 ms |
45856 KB |
Output is correct |
7 |
Correct |
402 ms |
46172 KB |
Output is correct |
8 |
Correct |
433 ms |
46464 KB |
Output is correct |
9 |
Correct |
375 ms |
46328 KB |
Output is correct |
10 |
Correct |
391 ms |
45452 KB |
Output is correct |
11 |
Correct |
371 ms |
46300 KB |
Output is correct |
12 |
Correct |
355 ms |
45276 KB |
Output is correct |
13 |
Correct |
366 ms |
46040 KB |
Output is correct |
14 |
Correct |
365 ms |
46008 KB |
Output is correct |
15 |
Correct |
390 ms |
46120 KB |
Output is correct |
16 |
Correct |
364 ms |
45776 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
9848 KB |
Output is correct |
2 |
Correct |
469 ms |
45092 KB |
Output is correct |
3 |
Correct |
471 ms |
44380 KB |
Output is correct |
4 |
Correct |
469 ms |
45668 KB |
Output is correct |
5 |
Correct |
414 ms |
44608 KB |
Output is correct |
6 |
Correct |
394 ms |
44892 KB |
Output is correct |
7 |
Correct |
399 ms |
45120 KB |
Output is correct |
8 |
Correct |
434 ms |
45000 KB |
Output is correct |
9 |
Correct |
447 ms |
44476 KB |
Output is correct |
10 |
Correct |
410 ms |
44288 KB |
Output is correct |
11 |
Correct |
423 ms |
45540 KB |
Output is correct |
12 |
Correct |
424 ms |
45056 KB |
Output is correct |
13 |
Correct |
402 ms |
45380 KB |
Output is correct |
14 |
Correct |
414 ms |
44548 KB |
Output is correct |
15 |
Correct |
408 ms |
45380 KB |
Output is correct |
16 |
Correct |
406 ms |
45056 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
364 ms |
46748 KB |
Output is correct |
2 |
Correct |
346 ms |
47068 KB |
Output is correct |
3 |
Correct |
368 ms |
47840 KB |
Output is correct |
4 |
Correct |
359 ms |
46808 KB |
Output is correct |
5 |
Correct |
356 ms |
46844 KB |
Output is correct |
6 |
Correct |
356 ms |
47020 KB |
Output is correct |
7 |
Correct |
347 ms |
47576 KB |
Output is correct |
8 |
Correct |
366 ms |
47328 KB |
Output is correct |
9 |
Correct |
347 ms |
46860 KB |
Output is correct |
10 |
Correct |
361 ms |
47432 KB |
Output is correct |
11 |
Correct |
362 ms |
47124 KB |
Output is correct |
12 |
Correct |
381 ms |
47308 KB |
Output is correct |
13 |
Correct |
373 ms |
47040 KB |
Output is correct |
14 |
Correct |
414 ms |
47192 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
9848 KB |
Output is correct |
2 |
Correct |
12 ms |
9848 KB |
Output is correct |
3 |
Correct |
12 ms |
9848 KB |
Output is correct |
4 |
Correct |
10 ms |
9900 KB |
Output is correct |
5 |
Correct |
12 ms |
9848 KB |
Output is correct |
6 |
Correct |
11 ms |
9824 KB |
Output is correct |
7 |
Correct |
10 ms |
9848 KB |
Output is correct |
8 |
Correct |
10 ms |
9852 KB |
Output is correct |
9 |
Correct |
12 ms |
9848 KB |
Output is correct |
10 |
Correct |
10 ms |
9848 KB |
Output is correct |
11 |
Correct |
12 ms |
9848 KB |
Output is correct |
12 |
Correct |
14 ms |
9848 KB |
Output is correct |
13 |
Correct |
14 ms |
9848 KB |
Output is correct |
14 |
Correct |
12 ms |
9848 KB |
Output is correct |
15 |
Correct |
12 ms |
9848 KB |
Output is correct |
16 |
Correct |
12 ms |
9848 KB |
Output is correct |
17 |
Correct |
11 ms |
9848 KB |
Output is correct |
18 |
Correct |
11 ms |
9876 KB |
Output is correct |
19 |
Correct |
11 ms |
9848 KB |
Output is correct |
20 |
Correct |
14 ms |
9880 KB |
Output is correct |
21 |
Correct |
14 ms |
9848 KB |
Output is correct |
22 |
Correct |
13 ms |
9848 KB |
Output is correct |
23 |
Correct |
11 ms |
9848 KB |
Output is correct |
24 |
Correct |
12 ms |
9896 KB |
Output is correct |
25 |
Correct |
11 ms |
9824 KB |
Output is correct |
26 |
Correct |
10 ms |
9848 KB |
Output is correct |
27 |
Correct |
25 ms |
9888 KB |
Output is correct |
28 |
Correct |
12 ms |
9848 KB |
Output is correct |
29 |
Correct |
11 ms |
9848 KB |
Output is correct |
30 |
Correct |
10 ms |
9848 KB |
Output is correct |
31 |
Correct |
10 ms |
9848 KB |
Output is correct |
32 |
Correct |
11 ms |
9840 KB |
Output is correct |
33 |
Correct |
461 ms |
45760 KB |
Output is correct |
34 |
Correct |
443 ms |
46300 KB |
Output is correct |
35 |
Correct |
456 ms |
46248 KB |
Output is correct |
36 |
Correct |
398 ms |
45644 KB |
Output is correct |
37 |
Correct |
425 ms |
45528 KB |
Output is correct |
38 |
Correct |
410 ms |
46168 KB |
Output is correct |
39 |
Correct |
453 ms |
45788 KB |
Output is correct |
40 |
Correct |
406 ms |
45400 KB |
Output is correct |
41 |
Correct |
473 ms |
46168 KB |
Output is correct |
42 |
Correct |
436 ms |
45660 KB |
Output is correct |
43 |
Correct |
399 ms |
46504 KB |
Output is correct |
44 |
Correct |
404 ms |
46304 KB |
Output is correct |
45 |
Correct |
390 ms |
45276 KB |
Output is correct |
46 |
Correct |
381 ms |
46168 KB |
Output is correct |
47 |
Correct |
401 ms |
45528 KB |
Output is correct |
48 |
Correct |
392 ms |
45144 KB |
Output is correct |
49 |
Correct |
376 ms |
45792 KB |
Output is correct |
50 |
Correct |
414 ms |
46556 KB |
Output is correct |
51 |
Correct |
376 ms |
46420 KB |
Output is correct |
52 |
Correct |
384 ms |
45912 KB |
Output is correct |
53 |
Correct |
401 ms |
45912 KB |
Output is correct |
54 |
Correct |
403 ms |
45656 KB |
Output is correct |
55 |
Correct |
425 ms |
45788 KB |
Output is correct |
56 |
Correct |
407 ms |
46180 KB |
Output is correct |
57 |
Correct |
412 ms |
45784 KB |
Output is correct |
58 |
Correct |
400 ms |
46424 KB |
Output is correct |
59 |
Correct |
365 ms |
45836 KB |
Output is correct |
60 |
Correct |
364 ms |
45516 KB |
Output is correct |
61 |
Correct |
452 ms |
45960 KB |
Output is correct |
62 |
Correct |
402 ms |
46144 KB |
Output is correct |
63 |
Correct |
380 ms |
45856 KB |
Output is correct |
64 |
Correct |
402 ms |
46172 KB |
Output is correct |
65 |
Correct |
433 ms |
46464 KB |
Output is correct |
66 |
Correct |
375 ms |
46328 KB |
Output is correct |
67 |
Correct |
391 ms |
45452 KB |
Output is correct |
68 |
Correct |
371 ms |
46300 KB |
Output is correct |
69 |
Correct |
355 ms |
45276 KB |
Output is correct |
70 |
Correct |
366 ms |
46040 KB |
Output is correct |
71 |
Correct |
365 ms |
46008 KB |
Output is correct |
72 |
Correct |
390 ms |
46120 KB |
Output is correct |
73 |
Correct |
364 ms |
45776 KB |
Output is correct |
74 |
Correct |
469 ms |
45092 KB |
Output is correct |
75 |
Correct |
471 ms |
44380 KB |
Output is correct |
76 |
Correct |
469 ms |
45668 KB |
Output is correct |
77 |
Correct |
414 ms |
44608 KB |
Output is correct |
78 |
Correct |
394 ms |
44892 KB |
Output is correct |
79 |
Correct |
399 ms |
45120 KB |
Output is correct |
80 |
Correct |
434 ms |
45000 KB |
Output is correct |
81 |
Correct |
447 ms |
44476 KB |
Output is correct |
82 |
Correct |
410 ms |
44288 KB |
Output is correct |
83 |
Correct |
423 ms |
45540 KB |
Output is correct |
84 |
Correct |
424 ms |
45056 KB |
Output is correct |
85 |
Correct |
402 ms |
45380 KB |
Output is correct |
86 |
Correct |
414 ms |
44548 KB |
Output is correct |
87 |
Correct |
408 ms |
45380 KB |
Output is correct |
88 |
Correct |
406 ms |
45056 KB |
Output is correct |
89 |
Correct |
364 ms |
46748 KB |
Output is correct |
90 |
Correct |
346 ms |
47068 KB |
Output is correct |
91 |
Correct |
368 ms |
47840 KB |
Output is correct |
92 |
Correct |
359 ms |
46808 KB |
Output is correct |
93 |
Correct |
356 ms |
46844 KB |
Output is correct |
94 |
Correct |
356 ms |
47020 KB |
Output is correct |
95 |
Correct |
347 ms |
47576 KB |
Output is correct |
96 |
Correct |
366 ms |
47328 KB |
Output is correct |
97 |
Correct |
347 ms |
46860 KB |
Output is correct |
98 |
Correct |
361 ms |
47432 KB |
Output is correct |
99 |
Correct |
362 ms |
47124 KB |
Output is correct |
100 |
Correct |
381 ms |
47308 KB |
Output is correct |
101 |
Correct |
373 ms |
47040 KB |
Output is correct |
102 |
Correct |
414 ms |
47192 KB |
Output is correct |