# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
259602 |
2020-08-08T03:49:01 Z |
송준혁(#5058) |
역사적 조사 (JOI14_historical) |
C++17 |
|
4000 ms |
68340 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=300;
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 |
5 ms |
768 KB |
Output is correct |
18 |
Correct |
11 ms |
1528 KB |
Output is correct |
19 |
Correct |
22 ms |
1528 KB |
Output is correct |
20 |
Correct |
57 ms |
1656 KB |
Output is correct |
21 |
Correct |
97 ms |
2676 KB |
Output is correct |
22 |
Correct |
93 ms |
2676 KB |
Output is correct |
23 |
Correct |
94 ms |
1656 KB |
Output is correct |
24 |
Correct |
99 ms |
1656 KB |
Output is correct |
25 |
Correct |
67 ms |
4708 KB |
Output is correct |
26 |
Correct |
71 ms |
4708 KB |
Output is correct |
27 |
Correct |
74 ms |
4836 KB |
Output is correct |
28 |
Correct |
66 ms |
4708 KB |
Output is correct |
29 |
Correct |
81 ms |
4708 KB |
Output is correct |
30 |
Correct |
88 ms |
4840 KB |
Output is correct |
31 |
Correct |
96 ms |
1656 KB |
Output is correct |
32 |
Correct |
88 ms |
1656 KB |
Output is correct |
33 |
Correct |
77 ms |
4708 KB |
Output is correct |
34 |
Correct |
74 ms |
4720 KB |
Output is correct |
35 |
Correct |
55 ms |
4836 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
384 KB |
Output is correct |
2 |
Correct |
1 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 |
384 KB |
Output is correct |
7 |
Correct |
3 ms |
640 KB |
Output is correct |
8 |
Correct |
6 ms |
896 KB |
Output is correct |
9 |
Correct |
12 ms |
1404 KB |
Output is correct |
10 |
Correct |
22 ms |
1400 KB |
Output is correct |
11 |
Correct |
108 ms |
5208 KB |
Output is correct |
12 |
Correct |
54 ms |
4076 KB |
Output is correct |
13 |
Correct |
71 ms |
4588 KB |
Output is correct |
14 |
Correct |
96 ms |
4712 KB |
Output is correct |
15 |
Correct |
119 ms |
5480 KB |
Output is correct |
16 |
Correct |
80 ms |
5864 KB |
Output is correct |
17 |
Correct |
47 ms |
4840 KB |
Output is correct |
18 |
Correct |
78 ms |
7400 KB |
Output is correct |
19 |
Correct |
78 ms |
6756 KB |
Output is correct |
20 |
Correct |
42 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 |
5 ms |
768 KB |
Output is correct |
18 |
Correct |
11 ms |
1528 KB |
Output is correct |
19 |
Correct |
22 ms |
1528 KB |
Output is correct |
20 |
Correct |
57 ms |
1656 KB |
Output is correct |
21 |
Correct |
97 ms |
2676 KB |
Output is correct |
22 |
Correct |
93 ms |
2676 KB |
Output is correct |
23 |
Correct |
94 ms |
1656 KB |
Output is correct |
24 |
Correct |
99 ms |
1656 KB |
Output is correct |
25 |
Correct |
67 ms |
4708 KB |
Output is correct |
26 |
Correct |
71 ms |
4708 KB |
Output is correct |
27 |
Correct |
74 ms |
4836 KB |
Output is correct |
28 |
Correct |
66 ms |
4708 KB |
Output is correct |
29 |
Correct |
81 ms |
4708 KB |
Output is correct |
30 |
Correct |
88 ms |
4840 KB |
Output is correct |
31 |
Correct |
96 ms |
1656 KB |
Output is correct |
32 |
Correct |
88 ms |
1656 KB |
Output is correct |
33 |
Correct |
77 ms |
4708 KB |
Output is correct |
34 |
Correct |
74 ms |
4720 KB |
Output is correct |
35 |
Correct |
55 ms |
4836 KB |
Output is correct |
36 |
Correct |
0 ms |
384 KB |
Output is correct |
37 |
Correct |
1 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 |
384 KB |
Output is correct |
42 |
Correct |
3 ms |
640 KB |
Output is correct |
43 |
Correct |
6 ms |
896 KB |
Output is correct |
44 |
Correct |
12 ms |
1404 KB |
Output is correct |
45 |
Correct |
22 ms |
1400 KB |
Output is correct |
46 |
Correct |
108 ms |
5208 KB |
Output is correct |
47 |
Correct |
54 ms |
4076 KB |
Output is correct |
48 |
Correct |
71 ms |
4588 KB |
Output is correct |
49 |
Correct |
96 ms |
4712 KB |
Output is correct |
50 |
Correct |
119 ms |
5480 KB |
Output is correct |
51 |
Correct |
80 ms |
5864 KB |
Output is correct |
52 |
Correct |
47 ms |
4840 KB |
Output is correct |
53 |
Correct |
78 ms |
7400 KB |
Output is correct |
54 |
Correct |
78 ms |
6756 KB |
Output is correct |
55 |
Correct |
42 ms |
4968 KB |
Output is correct |
56 |
Correct |
230 ms |
2932 KB |
Output is correct |
57 |
Correct |
617 ms |
9428 KB |
Output is correct |
58 |
Correct |
956 ms |
34368 KB |
Output is correct |
59 |
Correct |
1631 ms |
67608 KB |
Output is correct |
60 |
Correct |
1956 ms |
67996 KB |
Output is correct |
61 |
Correct |
3447 ms |
68340 KB |
Output is correct |
62 |
Execution timed out |
4077 ms |
19324 KB |
Time limit exceeded |
63 |
Halted |
0 ms |
0 KB |
- |