답안 #56107

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
56107 2018-07-10T04:09:55 Z 테스트(#2091) Sushi (JOI16_sushi) C++11
100 / 100
7095 ms 242948 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <functional>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cstdlib>
 
using namespace std;
typedef long long llong;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<llong, llong> pll;
 
const int t = 700;
int n, q, g;
int v[400000];
priority_queue<int> mx[t];
priority_queue<int, vector<int>, greater<int>> pass[t];
 
void reconstruct(int x) {
    for (int i = x * t; i < (x + 1) * t && i < n; ++i) {
        pass[x].push(v[i]);
        v[i] = pass[x].top();
        pass[x].pop();
    }
    while (!pass[x].empty()) pass[x].pop();
}
 
void construct(int x) {
    while (!mx[x].empty()) mx[x].pop();
    for (int i = x * t; i < (x + 1) * t && i < n; ++i) {
        mx[x].push(v[i]);
    }
}
 
int main() {
    scanf("%d%d", &n, &q);
    for (int i = 0; i < n; ++i) {
        scanf("%d", v + i);
    }
    g = (n - 1) / t + 1;
    for (int i = 0; i < t; ++i) {
        for (int j = i * t; j < (i + 1) * t && j < n; ++j) {
            mx[i].push(v[j]);
        }
    }
    while (q--) {
        int s, e, p;
        scanf("%d%d%d", &s, &e, &p);
        --s; --e;
        int sg = s / t;
        int eg = e / t;
        reconstruct(sg);
        if (sg != eg) reconstruct(eg);
        if (sg == eg && s <= e) {
            for (int i = s; i <= e; ++i) {
                if (p < v[i]) swap(p, v[i]);
            }
        }
        else {
            for (int i = s; i < (sg + 1) * t && i < n; ++i) {
                if (p < v[i]) swap(p, v[i]);
            }
            for (int i = (sg + 1) % g; i != eg; i = (i + 1) % g) {
                pass[i].push(p);
                mx[i].push(p);
                p = mx[i].top();
                mx[i].pop();
            }
            for (int i = eg * t; i <= e; ++i) {
                if (p < v[i]) swap(p, v[i]);
            }
        }
        construct(sg);
        if (sg != eg) construct(eg);
        printf("%d\n", p);
    }
	return 0;
}

Compilation message

telegraph.cpp: In function 'int main()':
telegraph.cpp:44:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &q);
     ~~~~~^~~~~~~~~~~~~~~~
telegraph.cpp:46:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", v + i);
         ~~~~~^~~~~~~~~~~~~
telegraph.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &s, &e, &p);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 252 ms 632 KB Output is correct
2 Correct 211 ms 716 KB Output is correct
3 Correct 243 ms 716 KB Output is correct
4 Correct 217 ms 912 KB Output is correct
5 Correct 222 ms 912 KB Output is correct
6 Correct 243 ms 1032 KB Output is correct
7 Correct 110 ms 1032 KB Output is correct
8 Correct 113 ms 1032 KB Output is correct
9 Correct 225 ms 1104 KB Output is correct
10 Correct 238 ms 1268 KB Output is correct
11 Correct 234 ms 1356 KB Output is correct
12 Correct 241 ms 1436 KB Output is correct
13 Correct 241 ms 1532 KB Output is correct
14 Correct 162 ms 1532 KB Output is correct
15 Correct 181 ms 1636 KB Output is correct
16 Correct 170 ms 1636 KB Output is correct
17 Correct 2 ms 1636 KB Output is correct
18 Correct 2 ms 1636 KB Output is correct
19 Correct 3 ms 1636 KB Output is correct
20 Correct 3 ms 1636 KB Output is correct
21 Correct 1 ms 1636 KB Output is correct
22 Correct 3 ms 1636 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6204 ms 75796 KB Output is correct
2 Correct 5577 ms 78716 KB Output is correct
3 Correct 2361 ms 79392 KB Output is correct
4 Correct 5792 ms 84288 KB Output is correct
5 Correct 4681 ms 88416 KB Output is correct
6 Correct 5719 ms 92916 KB Output is correct
7 Correct 5631 ms 97484 KB Output is correct
8 Correct 6042 ms 101692 KB Output is correct
9 Correct 2262 ms 102692 KB Output is correct
10 Correct 4864 ms 105772 KB Output is correct
11 Correct 2186 ms 106568 KB Output is correct
12 Correct 4739 ms 109752 KB Output is correct
13 Correct 5696 ms 114072 KB Output is correct
14 Correct 5390 ms 117132 KB Output is correct
15 Correct 2485 ms 118040 KB Output is correct
16 Correct 5891 ms 122500 KB Output is correct
17 Correct 4743 ms 127168 KB Output is correct
18 Correct 5363 ms 131448 KB Output is correct
19 Correct 5572 ms 135804 KB Output is correct
20 Correct 5392 ms 140196 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 252 ms 632 KB Output is correct
2 Correct 211 ms 716 KB Output is correct
3 Correct 243 ms 716 KB Output is correct
4 Correct 217 ms 912 KB Output is correct
5 Correct 222 ms 912 KB Output is correct
6 Correct 243 ms 1032 KB Output is correct
7 Correct 110 ms 1032 KB Output is correct
8 Correct 113 ms 1032 KB Output is correct
9 Correct 225 ms 1104 KB Output is correct
10 Correct 238 ms 1268 KB Output is correct
11 Correct 234 ms 1356 KB Output is correct
12 Correct 241 ms 1436 KB Output is correct
13 Correct 241 ms 1532 KB Output is correct
14 Correct 162 ms 1532 KB Output is correct
15 Correct 181 ms 1636 KB Output is correct
16 Correct 170 ms 1636 KB Output is correct
17 Correct 2 ms 1636 KB Output is correct
18 Correct 2 ms 1636 KB Output is correct
19 Correct 3 ms 1636 KB Output is correct
20 Correct 3 ms 1636 KB Output is correct
21 Correct 1 ms 1636 KB Output is correct
22 Correct 3 ms 1636 KB Output is correct
23 Correct 6204 ms 75796 KB Output is correct
24 Correct 5577 ms 78716 KB Output is correct
25 Correct 2361 ms 79392 KB Output is correct
26 Correct 5792 ms 84288 KB Output is correct
27 Correct 4681 ms 88416 KB Output is correct
28 Correct 5719 ms 92916 KB Output is correct
29 Correct 5631 ms 97484 KB Output is correct
30 Correct 6042 ms 101692 KB Output is correct
31 Correct 2262 ms 102692 KB Output is correct
32 Correct 4864 ms 105772 KB Output is correct
33 Correct 2186 ms 106568 KB Output is correct
34 Correct 4739 ms 109752 KB Output is correct
35 Correct 5696 ms 114072 KB Output is correct
36 Correct 5390 ms 117132 KB Output is correct
37 Correct 2485 ms 118040 KB Output is correct
38 Correct 5891 ms 122500 KB Output is correct
39 Correct 4743 ms 127168 KB Output is correct
40 Correct 5363 ms 131448 KB Output is correct
41 Correct 5572 ms 135804 KB Output is correct
42 Correct 5392 ms 140196 KB Output is correct
43 Correct 5861 ms 140196 KB Output is correct
44 Correct 5839 ms 140196 KB Output is correct
45 Correct 3773 ms 140196 KB Output is correct
46 Correct 6111 ms 140196 KB Output is correct
47 Correct 5774 ms 140196 KB Output is correct
48 Correct 6545 ms 140196 KB Output is correct
49 Correct 6720 ms 140196 KB Output is correct
50 Correct 6954 ms 140196 KB Output is correct
51 Correct 7095 ms 140196 KB Output is correct
52 Correct 5587 ms 140196 KB Output is correct
53 Correct 5305 ms 140196 KB Output is correct
54 Correct 5923 ms 140196 KB Output is correct
55 Correct 5933 ms 140196 KB Output is correct
56 Correct 6389 ms 141668 KB Output is correct
57 Correct 6220 ms 146156 KB Output is correct
58 Correct 6010 ms 146712 KB Output is correct
59 Correct 5340 ms 151244 KB Output is correct
60 Correct 5168 ms 217096 KB Output is correct
61 Correct 5822 ms 221448 KB Output is correct
62 Correct 5417 ms 226244 KB Output is correct
63 Correct 5473 ms 230444 KB Output is correct
64 Correct 2555 ms 230444 KB Output is correct
65 Correct 3244 ms 230444 KB Output is correct
66 Correct 3418 ms 230444 KB Output is correct
67 Correct 4769 ms 230444 KB Output is correct
68 Correct 5301 ms 233884 KB Output is correct
69 Correct 5214 ms 238480 KB Output is correct
70 Correct 5160 ms 242948 KB Output is correct