# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
55115 |
2018-07-06T05:16:06 Z |
ainta(#1558) |
Sushi (JOI16_sushi) |
C++11 |
|
8673 ms |
51036 KB |
#include<cstdio>
#include<algorithm>
#include<queue>
#define BB 10
using namespace std;
int n, Q;
struct point {
int P[1<<BB], SZ;
vector<int>U;
priority_queue<int>PQ;
void Make() {
int i;
while (!PQ.empty())PQ.pop();
for (i = 0; i < SZ; i++) {
PQ.push(P[i]);
}
}
void init() {
priority_queue<int>PP;
for (auto &t : U) {
PP.push(-t);
}
int i;
for (i = 0; i < SZ; i++) {
PP.push(-P[i]);
P[i] = -PP.top();
PP.pop();
}
U.clear();
}
int Go(int x) {
U.push_back(x);
PQ.push(x);
int ret = PQ.top();
PQ.pop();
return ret;
}
}w[(400000>>BB)+2];
int Do(int b, int e, int x) {
for (int i = (b >> BB); i <= (e >> BB); i++) {
int bb = (i << BB), ee = min(((i + 1) << BB) - 1, n - 1);
if (b <= bb && ee <= e) {
x = w[i].Go(x);
}
else{
w[i].init();
bb = max(b, bb)&((1 << BB) - 1);
ee = min(e, ee)&((1 << BB) - 1);
for (int j = bb; j <= ee; j++) {
if (w[i].P[j] > x) {
swap(w[i].P[j], x);
}
}
w[i].Make();
}
}
return x;
}
int main() {
int i, b, e, c;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
scanf("%d%d", &n, &Q);
for (i = 0; i < n; i++) {
scanf("%d", &w[i>>BB].P[i&((1<<BB)-1)]);
w[i >> BB].SZ++;
}
for (i = 0; i <= ((n - 1) >> BB); i++)w[i].Make();
while (Q--) {
scanf("%d%d%d", &b, &e, &c);
b--, e--;
if (b > e) {
printf("%d\n",Do(0, e, Do(b, n - 1, c)));
}
else {
printf("%d\n", Do(b, e, c));
}
}
return 0;
}
/*
#include<cstdio>
#include<algorithm>
using namespace std;
int n = 100, Q = 200;
int main() {
freopen("input.txt", "w", stdout);
srand(1879);
int i;
printf("%d %d\n", n, Q);
for (i = 1; i <= n; i++) {
printf("%d\n", rand() % 100 + 1);
}
for (i = 1; i <= Q; i++) {
printf("%d %d %d\n", rand() % n + 1, rand() % n + 1, rand() % 100 + 1);
}
}*/
/*
#include<cstdio>
#include<algorithm>
#include<queue>
#define BB 12
using namespace std;
int n, Q;
struct point {
int P[1 << BB], SZ;
int U[1 << BB], UC;
priority_queue<int>PQ;
void init() {
int i;
for (i = UC - 1; i >= 0; i--) {
P[U[i]] = PQ.top();
PQ.pop();
}
}
void Make() {
int i, Mx = -1;
UC = 0;
while (!PQ.empty())PQ.pop();
for (i = 0; i < SZ; i++) {
if (Mx < P[i]) {
Mx = P[i];
U[UC++] = i;
PQ.push(P[i]);
}
}
}
int Go(int x) {
PQ.push(x);
int ret = PQ.top();
PQ.pop();
return ret;
}
}w[(400000 >> BB) + 2];
int Do(int b, int e, int x) {
for (int i = (b >> BB); i <= (e >> BB); i++) {
int bb = (i << BB), ee = min(((i + 1) << BB) - 1, n - 1);
if (b <= bb && ee <= e) {
x = w[i].Go(x);
}
else {
w[i].init();
bb = max(b, bb)&((1 << BB) - 1);
ee = min(e, ee)&((1 << BB) - 1);
for (int j = bb; j <= ee; j++) {
if (w[i].P[j] > x) {
swap(w[i].P[j], x);
}
}
w[i].Make();
}
}
return x;
}
int main() {
int i, b, e, c;
freopen("input.txt", "r", stdin);
freopen("output2.txt", "w", stdout);
scanf("%d%d", &n, &Q);
for (i = 0; i < n; i++) {
scanf("%d", &w[i >> BB].P[i&((1 << BB) - 1)]);
w[i >> BB].SZ++;
}
for (i = 0; i <= ((n - 1) >> BB); i++)w[i].Make();
while (Q--) {
scanf("%d%d%d", &b, &e, &c);
b--, e--;
if (b > e) {
printf("%d\n", Do(0, e, Do(b, n - 1, c)));
}
else {
printf("%d\n", Do(b, e, c));
}
}
return 0;
}*/
Compilation message
telegraph.cpp: In function 'int main()':
telegraph.cpp:63:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &n, &Q);
~~~~~^~~~~~~~~~~~~~~~
telegraph.cpp:65:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &w[i>>BB].P[i&((1<<BB)-1)]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
telegraph.cpp:70:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d", &b, &e, &c);
~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
379 ms |
1952 KB |
Output is correct |
2 |
Correct |
427 ms |
2020 KB |
Output is correct |
3 |
Correct |
359 ms |
2072 KB |
Output is correct |
4 |
Correct |
371 ms |
2264 KB |
Output is correct |
5 |
Correct |
367 ms |
2264 KB |
Output is correct |
6 |
Correct |
388 ms |
2264 KB |
Output is correct |
7 |
Correct |
183 ms |
2264 KB |
Output is correct |
8 |
Correct |
179 ms |
2264 KB |
Output is correct |
9 |
Correct |
426 ms |
2376 KB |
Output is correct |
10 |
Correct |
375 ms |
2376 KB |
Output is correct |
11 |
Correct |
339 ms |
2376 KB |
Output is correct |
12 |
Correct |
375 ms |
2480 KB |
Output is correct |
13 |
Correct |
377 ms |
2480 KB |
Output is correct |
14 |
Correct |
447 ms |
2480 KB |
Output is correct |
15 |
Correct |
418 ms |
2480 KB |
Output is correct |
16 |
Correct |
240 ms |
2480 KB |
Output is correct |
17 |
Correct |
3 ms |
2480 KB |
Output is correct |
18 |
Correct |
3 ms |
2480 KB |
Output is correct |
19 |
Correct |
4 ms |
2480 KB |
Output is correct |
20 |
Correct |
4 ms |
2480 KB |
Output is correct |
21 |
Correct |
3 ms |
2480 KB |
Output is correct |
22 |
Correct |
4 ms |
2480 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2004 ms |
51036 KB |
Output is correct |
2 |
Correct |
1858 ms |
51036 KB |
Output is correct |
3 |
Correct |
1206 ms |
51036 KB |
Output is correct |
4 |
Correct |
1851 ms |
51036 KB |
Output is correct |
5 |
Correct |
1810 ms |
51036 KB |
Output is correct |
6 |
Correct |
1865 ms |
51036 KB |
Output is correct |
7 |
Correct |
1564 ms |
51036 KB |
Output is correct |
8 |
Correct |
1390 ms |
51036 KB |
Output is correct |
9 |
Correct |
1685 ms |
51036 KB |
Output is correct |
10 |
Correct |
1406 ms |
51036 KB |
Output is correct |
11 |
Correct |
1218 ms |
51036 KB |
Output is correct |
12 |
Correct |
1294 ms |
51036 KB |
Output is correct |
13 |
Correct |
2025 ms |
51036 KB |
Output is correct |
14 |
Correct |
1868 ms |
51036 KB |
Output is correct |
15 |
Correct |
1569 ms |
51036 KB |
Output is correct |
16 |
Correct |
1930 ms |
51036 KB |
Output is correct |
17 |
Correct |
1266 ms |
51036 KB |
Output is correct |
18 |
Correct |
1615 ms |
51036 KB |
Output is correct |
19 |
Correct |
1551 ms |
51036 KB |
Output is correct |
20 |
Correct |
1487 ms |
51036 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
379 ms |
1952 KB |
Output is correct |
2 |
Correct |
427 ms |
2020 KB |
Output is correct |
3 |
Correct |
359 ms |
2072 KB |
Output is correct |
4 |
Correct |
371 ms |
2264 KB |
Output is correct |
5 |
Correct |
367 ms |
2264 KB |
Output is correct |
6 |
Correct |
388 ms |
2264 KB |
Output is correct |
7 |
Correct |
183 ms |
2264 KB |
Output is correct |
8 |
Correct |
179 ms |
2264 KB |
Output is correct |
9 |
Correct |
426 ms |
2376 KB |
Output is correct |
10 |
Correct |
375 ms |
2376 KB |
Output is correct |
11 |
Correct |
339 ms |
2376 KB |
Output is correct |
12 |
Correct |
375 ms |
2480 KB |
Output is correct |
13 |
Correct |
377 ms |
2480 KB |
Output is correct |
14 |
Correct |
447 ms |
2480 KB |
Output is correct |
15 |
Correct |
418 ms |
2480 KB |
Output is correct |
16 |
Correct |
240 ms |
2480 KB |
Output is correct |
17 |
Correct |
3 ms |
2480 KB |
Output is correct |
18 |
Correct |
3 ms |
2480 KB |
Output is correct |
19 |
Correct |
4 ms |
2480 KB |
Output is correct |
20 |
Correct |
4 ms |
2480 KB |
Output is correct |
21 |
Correct |
3 ms |
2480 KB |
Output is correct |
22 |
Correct |
4 ms |
2480 KB |
Output is correct |
23 |
Correct |
2004 ms |
51036 KB |
Output is correct |
24 |
Correct |
1858 ms |
51036 KB |
Output is correct |
25 |
Correct |
1206 ms |
51036 KB |
Output is correct |
26 |
Correct |
1851 ms |
51036 KB |
Output is correct |
27 |
Correct |
1810 ms |
51036 KB |
Output is correct |
28 |
Correct |
1865 ms |
51036 KB |
Output is correct |
29 |
Correct |
1564 ms |
51036 KB |
Output is correct |
30 |
Correct |
1390 ms |
51036 KB |
Output is correct |
31 |
Correct |
1685 ms |
51036 KB |
Output is correct |
32 |
Correct |
1406 ms |
51036 KB |
Output is correct |
33 |
Correct |
1218 ms |
51036 KB |
Output is correct |
34 |
Correct |
1294 ms |
51036 KB |
Output is correct |
35 |
Correct |
2025 ms |
51036 KB |
Output is correct |
36 |
Correct |
1868 ms |
51036 KB |
Output is correct |
37 |
Correct |
1569 ms |
51036 KB |
Output is correct |
38 |
Correct |
1930 ms |
51036 KB |
Output is correct |
39 |
Correct |
1266 ms |
51036 KB |
Output is correct |
40 |
Correct |
1615 ms |
51036 KB |
Output is correct |
41 |
Correct |
1551 ms |
51036 KB |
Output is correct |
42 |
Correct |
1487 ms |
51036 KB |
Output is correct |
43 |
Correct |
7709 ms |
51036 KB |
Output is correct |
44 |
Correct |
7574 ms |
51036 KB |
Output is correct |
45 |
Correct |
4940 ms |
51036 KB |
Output is correct |
46 |
Correct |
7657 ms |
51036 KB |
Output is correct |
47 |
Correct |
7679 ms |
51036 KB |
Output is correct |
48 |
Correct |
7837 ms |
51036 KB |
Output is correct |
49 |
Correct |
8592 ms |
51036 KB |
Output is correct |
50 |
Correct |
8270 ms |
51036 KB |
Output is correct |
51 |
Correct |
8673 ms |
51036 KB |
Output is correct |
52 |
Correct |
7751 ms |
51036 KB |
Output is correct |
53 |
Correct |
7354 ms |
51036 KB |
Output is correct |
54 |
Correct |
7614 ms |
51036 KB |
Output is correct |
55 |
Correct |
8276 ms |
51036 KB |
Output is correct |
56 |
Correct |
8473 ms |
51036 KB |
Output is correct |
57 |
Correct |
8525 ms |
51036 KB |
Output is correct |
58 |
Correct |
4513 ms |
51036 KB |
Output is correct |
59 |
Correct |
4852 ms |
51036 KB |
Output is correct |
60 |
Correct |
4928 ms |
51036 KB |
Output is correct |
61 |
Correct |
5716 ms |
51036 KB |
Output is correct |
62 |
Correct |
5585 ms |
51036 KB |
Output is correct |
63 |
Correct |
5726 ms |
51036 KB |
Output is correct |
64 |
Correct |
3384 ms |
51036 KB |
Output is correct |
65 |
Correct |
3861 ms |
51036 KB |
Output is correct |
66 |
Correct |
3928 ms |
51036 KB |
Output is correct |
67 |
Correct |
6562 ms |
51036 KB |
Output is correct |
68 |
Correct |
7010 ms |
51036 KB |
Output is correct |
69 |
Correct |
6582 ms |
51036 KB |
Output is correct |
70 |
Correct |
6473 ms |
51036 KB |
Output is correct |