# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
259601 |
2020-08-08T03:47:47 Z |
송준혁(#5058) |
역사적 조사 (JOI14_historical) |
C++17 |
|
4000 ms |
68324 KB |
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
#define Mup(a,x) a=max(a, x)
#define mup(a,x) a=min(a, x)
#define all(v) v.begin(),v.end()
#define lb lower_bound
#define INF (1ll<<60)
using namespace std;
typedef long long LL;
typedef pair<LL,LL> pii;
int N, Q, B=400;
LL A[101010], M[101010], ans[101010];
vector<LL> comp;
priority_queue<pii> S;
struct query{
int s, e, id;
} P[101010];
int main(){
scanf("%d %d", &N, &Q);
for (int i=1; i<=N; i++){
scanf("%lld", &A[i]);
comp.pb(A[i]);
}
for (int i=1; i<=Q; i++) scanf("%d %d", &P[i].s, &P[i].e), P[i].id=i;
sort(comp.begin(), comp.end());
comp.erase(unique(comp.begin(), comp.end()), comp.end());
for (int i=1; i<=N; i++) A[i] = lower_bound(comp.begin(), comp.end(), A[i])-comp.begin();
sort(P+1, P+Q+1, [&](query a, query b){
if (a.s/B == b.s/B) return a.e < b.e;
return a.s < b.s;
});
int l=1, r=1;
M[A[1]] = comp[A[1]];
S.push(pii(comp[A[1]], A[1]));
for (int i=1; i<=Q; i++){
for (int j=r+1; j<=P[i].e; j++){
M[A[j]] += comp[A[j]];
S.push(pii(M[A[j]], A[j]));
}
for (int j=P[i].s; j<l; j++) {
M[A[j]] += comp[A[j]];
S.push(pii(M[A[j]], A[j]));
}
for (int j=P[i].e+1; j<=r; j++) {
M[A[j]] -= comp[A[j]];
if (M[A[j]]) S.push(pii(M[A[j]], A[j]));
}
for (int j=l; j<P[i].s; j++) {
M[A[j]] -= comp[A[j]];
if (M[A[j]]) S.push(pii(M[A[j]], A[j]));
}
while (M[S.top().se] != S.top().fi) S.pop();
ans[P[i].id] = S.top().fi;
l=P[i].s, r=P[i].e;
}
for (int i=1; i<=Q; i++) printf("%lld\n", ans[i]);
return 0;
}
Compilation message
historic.cpp: In function 'int main()':
historic.cpp:24:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &Q);
~~~~~^~~~~~~~~~~~~~~~~
historic.cpp:26:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld", &A[i]);
~~~~~^~~~~~~~~~~~~~~
historic.cpp:29:59: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i=1; i<=Q; i++) scanf("%d %d", &P[i].s, &P[i].e), P[i].id=i;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
4 ms |
768 KB |
Output is correct |
18 |
Correct |
13 ms |
1528 KB |
Output is correct |
19 |
Correct |
31 ms |
2548 KB |
Output is correct |
20 |
Correct |
74 ms |
2676 KB |
Output is correct |
21 |
Correct |
125 ms |
2676 KB |
Output is correct |
22 |
Correct |
116 ms |
2676 KB |
Output is correct |
23 |
Correct |
121 ms |
2676 KB |
Output is correct |
24 |
Correct |
130 ms |
2676 KB |
Output is correct |
25 |
Correct |
78 ms |
4708 KB |
Output is correct |
26 |
Correct |
94 ms |
4708 KB |
Output is correct |
27 |
Correct |
93 ms |
4708 KB |
Output is correct |
28 |
Correct |
85 ms |
4848 KB |
Output is correct |
29 |
Correct |
106 ms |
4708 KB |
Output is correct |
30 |
Correct |
102 ms |
4708 KB |
Output is correct |
31 |
Correct |
128 ms |
2676 KB |
Output is correct |
32 |
Correct |
110 ms |
2676 KB |
Output is correct |
33 |
Correct |
96 ms |
4708 KB |
Output is correct |
34 |
Correct |
90 ms |
4712 KB |
Output is correct |
35 |
Correct |
67 ms |
8944 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
0 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
2 ms |
384 KB |
Output is correct |
6 |
Correct |
2 ms |
512 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
6 ms |
1024 KB |
Output is correct |
9 |
Correct |
12 ms |
1404 KB |
Output is correct |
10 |
Correct |
21 ms |
1400 KB |
Output is correct |
11 |
Correct |
115 ms |
5100 KB |
Output is correct |
12 |
Correct |
54 ms |
4076 KB |
Output is correct |
13 |
Correct |
74 ms |
4592 KB |
Output is correct |
14 |
Correct |
95 ms |
4840 KB |
Output is correct |
15 |
Correct |
120 ms |
5480 KB |
Output is correct |
16 |
Correct |
82 ms |
5868 KB |
Output is correct |
17 |
Correct |
45 ms |
4836 KB |
Output is correct |
18 |
Correct |
80 ms |
7400 KB |
Output is correct |
19 |
Correct |
79 ms |
6884 KB |
Output is correct |
20 |
Correct |
45 ms |
4968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
0 ms |
384 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
1 ms |
384 KB |
Output is correct |
8 |
Correct |
1 ms |
384 KB |
Output is correct |
9 |
Correct |
1 ms |
384 KB |
Output is correct |
10 |
Correct |
1 ms |
384 KB |
Output is correct |
11 |
Correct |
1 ms |
384 KB |
Output is correct |
12 |
Correct |
1 ms |
384 KB |
Output is correct |
13 |
Correct |
1 ms |
384 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
384 KB |
Output is correct |
16 |
Correct |
1 ms |
512 KB |
Output is correct |
17 |
Correct |
4 ms |
768 KB |
Output is correct |
18 |
Correct |
13 ms |
1528 KB |
Output is correct |
19 |
Correct |
31 ms |
2548 KB |
Output is correct |
20 |
Correct |
74 ms |
2676 KB |
Output is correct |
21 |
Correct |
125 ms |
2676 KB |
Output is correct |
22 |
Correct |
116 ms |
2676 KB |
Output is correct |
23 |
Correct |
121 ms |
2676 KB |
Output is correct |
24 |
Correct |
130 ms |
2676 KB |
Output is correct |
25 |
Correct |
78 ms |
4708 KB |
Output is correct |
26 |
Correct |
94 ms |
4708 KB |
Output is correct |
27 |
Correct |
93 ms |
4708 KB |
Output is correct |
28 |
Correct |
85 ms |
4848 KB |
Output is correct |
29 |
Correct |
106 ms |
4708 KB |
Output is correct |
30 |
Correct |
102 ms |
4708 KB |
Output is correct |
31 |
Correct |
128 ms |
2676 KB |
Output is correct |
32 |
Correct |
110 ms |
2676 KB |
Output is correct |
33 |
Correct |
96 ms |
4708 KB |
Output is correct |
34 |
Correct |
90 ms |
4712 KB |
Output is correct |
35 |
Correct |
67 ms |
8944 KB |
Output is correct |
36 |
Correct |
0 ms |
384 KB |
Output is correct |
37 |
Correct |
0 ms |
384 KB |
Output is correct |
38 |
Correct |
0 ms |
384 KB |
Output is correct |
39 |
Correct |
1 ms |
384 KB |
Output is correct |
40 |
Correct |
2 ms |
384 KB |
Output is correct |
41 |
Correct |
2 ms |
512 KB |
Output is correct |
42 |
Correct |
3 ms |
640 KB |
Output is correct |
43 |
Correct |
6 ms |
1024 KB |
Output is correct |
44 |
Correct |
12 ms |
1404 KB |
Output is correct |
45 |
Correct |
21 ms |
1400 KB |
Output is correct |
46 |
Correct |
115 ms |
5100 KB |
Output is correct |
47 |
Correct |
54 ms |
4076 KB |
Output is correct |
48 |
Correct |
74 ms |
4592 KB |
Output is correct |
49 |
Correct |
95 ms |
4840 KB |
Output is correct |
50 |
Correct |
120 ms |
5480 KB |
Output is correct |
51 |
Correct |
82 ms |
5868 KB |
Output is correct |
52 |
Correct |
45 ms |
4836 KB |
Output is correct |
53 |
Correct |
80 ms |
7400 KB |
Output is correct |
54 |
Correct |
79 ms |
6884 KB |
Output is correct |
55 |
Correct |
45 ms |
4968 KB |
Output is correct |
56 |
Correct |
295 ms |
2932 KB |
Output is correct |
57 |
Correct |
734 ms |
9436 KB |
Output is correct |
58 |
Correct |
1016 ms |
34540 KB |
Output is correct |
59 |
Correct |
1648 ms |
67868 KB |
Output is correct |
60 |
Correct |
1883 ms |
68128 KB |
Output is correct |
61 |
Correct |
3311 ms |
68324 KB |
Output is correct |
62 |
Execution timed out |
4067 ms |
19400 KB |
Time limit exceeded |
63 |
Halted |
0 ms |
0 KB |
- |