# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
199463 |
2020-02-01T13:11:49 Z |
dennisstar |
Sushi (JOI16_sushi) |
C++17 |
|
12000 ms |
11384 KB |
#include <bits/stdc++.h>
#define fi first
#define se second
#define em emplace
#define eb emplace_back
#define all(V) (V).begin(), (V).end()
using namespace std;
typedef vector<int> vim;
typedef pair<int, int> pii;
const int sz = 1000;
int N, M, Q, X[400010];
vector<pii> B[810]; priority_queue<int> S[810];
inline void make(int t) {
B[t].clear(); while(!S[t].empty()) S[t].pop();
int ub=min((t+1)*sz, N);
for (int i=t*sz; i<ub; i++) B[t].eb(X[i], i);
sort(all(B[t])); reverse(all(B[t]));
for (auto &i:B[t]) S[t].em(i.fi);
}
inline void upd(int t) {
for (auto &i:B[t]) { i.fi=S[t].top(); X[i.se]=i.fi; S[t].pop(); }
for (auto &i:B[t]) S[t].em(i.fi);
}
inline int sol(int t, int p) {
S[t].em(p); p=S[t].top(); S[t].pop();
return p;
}
inline int f(int s, int e, int p) {
int st=s/sz, et=e/sz;
upd(st); upd(et);
if (st==et) { for (int i=s; i<=e; i++) if (p<X[i]) swap(p, X[i]); }
else {
for (int i=s; i<min(N, (st+1)*sz); i++) if (p<X[i]) swap(p, X[i]);
for (int i=st+1; i<et; i++) p=sol(i, p);
for (int i=et*sz; i<=e; i++) if (p<X[i]) swap(p, X[i]);
}
make(st); make(et);
return p;
}
int main() {
scanf("%d %d", &N, &Q); M=(N+sz-1)/sz;
for (int i=0; i<N; i++) scanf("%d", &X[i]);
for (int i=0; i<M; i++) make(i);
while (Q--) {
int s, t, p;
scanf("%d %d %d", &s, &t, &p); s--; t--;
if (s>t) printf("%d\n", f(0, t, f(s, N-1, p)));
else printf("%d\n", f(s, t, p));
}
return 0;
}
Compilation message
sushi.cpp: In function 'int main()':
sushi.cpp:48:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &N, &Q); M=(N+sz-1)/sz;
~~~~~^~~~~~~~~~~~~~~~~
sushi.cpp:49:31: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for (int i=0; i<N; i++) scanf("%d", &X[i]);
~~~~~^~~~~~~~~~~~~
sushi.cpp:53:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d %d", &s, &t, &p); s--; t--;
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1177 ms |
632 KB |
Output is correct |
2 |
Correct |
1162 ms |
632 KB |
Output is correct |
3 |
Correct |
1194 ms |
632 KB |
Output is correct |
4 |
Correct |
1164 ms |
508 KB |
Output is correct |
5 |
Correct |
1245 ms |
632 KB |
Output is correct |
6 |
Correct |
1264 ms |
508 KB |
Output is correct |
7 |
Correct |
645 ms |
504 KB |
Output is correct |
8 |
Correct |
628 ms |
476 KB |
Output is correct |
9 |
Correct |
1168 ms |
532 KB |
Output is correct |
10 |
Correct |
1160 ms |
504 KB |
Output is correct |
11 |
Correct |
1154 ms |
504 KB |
Output is correct |
12 |
Correct |
1115 ms |
768 KB |
Output is correct |
13 |
Correct |
1220 ms |
760 KB |
Output is correct |
14 |
Correct |
1541 ms |
632 KB |
Output is correct |
15 |
Correct |
1517 ms |
532 KB |
Output is correct |
16 |
Correct |
726 ms |
504 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10015 ms |
7480 KB |
Output is correct |
2 |
Correct |
10215 ms |
7388 KB |
Output is correct |
3 |
Correct |
4829 ms |
7204 KB |
Output is correct |
4 |
Correct |
9810 ms |
7412 KB |
Output is correct |
5 |
Correct |
7745 ms |
7472 KB |
Output is correct |
6 |
Correct |
9425 ms |
7324 KB |
Output is correct |
7 |
Correct |
9413 ms |
7480 KB |
Output is correct |
8 |
Correct |
9154 ms |
7484 KB |
Output is correct |
9 |
Correct |
3594 ms |
7192 KB |
Output is correct |
10 |
Correct |
7710 ms |
7348 KB |
Output is correct |
11 |
Correct |
3753 ms |
7192 KB |
Output is correct |
12 |
Correct |
8041 ms |
7416 KB |
Output is correct |
13 |
Correct |
10618 ms |
7568 KB |
Output is correct |
14 |
Correct |
9672 ms |
6904 KB |
Output is correct |
15 |
Correct |
4997 ms |
6776 KB |
Output is correct |
16 |
Correct |
9482 ms |
7032 KB |
Output is correct |
17 |
Correct |
7765 ms |
7148 KB |
Output is correct |
18 |
Correct |
9516 ms |
7048 KB |
Output is correct |
19 |
Correct |
9509 ms |
7088 KB |
Output is correct |
20 |
Correct |
9391 ms |
7160 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1177 ms |
632 KB |
Output is correct |
2 |
Correct |
1162 ms |
632 KB |
Output is correct |
3 |
Correct |
1194 ms |
632 KB |
Output is correct |
4 |
Correct |
1164 ms |
508 KB |
Output is correct |
5 |
Correct |
1245 ms |
632 KB |
Output is correct |
6 |
Correct |
1264 ms |
508 KB |
Output is correct |
7 |
Correct |
645 ms |
504 KB |
Output is correct |
8 |
Correct |
628 ms |
476 KB |
Output is correct |
9 |
Correct |
1168 ms |
532 KB |
Output is correct |
10 |
Correct |
1160 ms |
504 KB |
Output is correct |
11 |
Correct |
1154 ms |
504 KB |
Output is correct |
12 |
Correct |
1115 ms |
768 KB |
Output is correct |
13 |
Correct |
1220 ms |
760 KB |
Output is correct |
14 |
Correct |
1541 ms |
632 KB |
Output is correct |
15 |
Correct |
1517 ms |
532 KB |
Output is correct |
16 |
Correct |
726 ms |
504 KB |
Output is correct |
17 |
Correct |
5 ms |
376 KB |
Output is correct |
18 |
Correct |
5 ms |
376 KB |
Output is correct |
19 |
Correct |
6 ms |
376 KB |
Output is correct |
20 |
Correct |
6 ms |
376 KB |
Output is correct |
21 |
Correct |
5 ms |
376 KB |
Output is correct |
22 |
Correct |
5 ms |
376 KB |
Output is correct |
23 |
Correct |
10015 ms |
7480 KB |
Output is correct |
24 |
Correct |
10215 ms |
7388 KB |
Output is correct |
25 |
Correct |
4829 ms |
7204 KB |
Output is correct |
26 |
Correct |
9810 ms |
7412 KB |
Output is correct |
27 |
Correct |
7745 ms |
7472 KB |
Output is correct |
28 |
Correct |
9425 ms |
7324 KB |
Output is correct |
29 |
Correct |
9413 ms |
7480 KB |
Output is correct |
30 |
Correct |
9154 ms |
7484 KB |
Output is correct |
31 |
Correct |
3594 ms |
7192 KB |
Output is correct |
32 |
Correct |
7710 ms |
7348 KB |
Output is correct |
33 |
Correct |
3753 ms |
7192 KB |
Output is correct |
34 |
Correct |
8041 ms |
7416 KB |
Output is correct |
35 |
Correct |
10618 ms |
7568 KB |
Output is correct |
36 |
Correct |
9672 ms |
6904 KB |
Output is correct |
37 |
Correct |
4997 ms |
6776 KB |
Output is correct |
38 |
Correct |
9482 ms |
7032 KB |
Output is correct |
39 |
Correct |
7765 ms |
7148 KB |
Output is correct |
40 |
Correct |
9516 ms |
7048 KB |
Output is correct |
41 |
Correct |
9509 ms |
7088 KB |
Output is correct |
42 |
Correct |
9391 ms |
7160 KB |
Output is correct |
43 |
Execution timed out |
12067 ms |
11384 KB |
Time limit exceeded |
44 |
Halted |
0 ms |
0 KB |
- |