답안 #231338

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
231338 2020-05-13T11:30:31 Z maskoff Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1512 ms 79188 KB
#include <bits/stdc++.h>
#include <ext/rope>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
 
#define file ""
 
#define all(x) x.begin(), x.end()
 
#define sc second
#define fr first
 
#define pb push_back
#define mp make_pair

#define pss pair<line*, line*>
 
using namespace std;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef pair <int, int> pii;
                                    
const int inf = 1e9;
const int MOD = 1e9 + 7;
                                          
const int dx[] = {+1, -1, 0, 0};
const int dy[] = {0, 0, +1, -1};

int const N = 1e6 + 1;

int n, q;

struct line {
 	int r;
 	int l;
 	int k;
 	int pos;
};
vector<line> all;
vector<int> t, a;
int pos[N];

bool cmp(line a, line b) {
 	return a.r < b.r;
}

void update (int u, int l, int r, int pos, int val) {
 	if (r == l) {
 	 	t[u] = val;
 	 	return;
 	}
 	int m = l + r >> 1;
 	if (pos <= m) update (u + u, l, m, pos, val);
 	else update (u + u + 1, m + 1, r, pos, val);
 	t[u] = max(t[u + u], t[u + u + 1]);
}

int get (int u, int ul, int ur, int l, int r) {
 	if (l > ur || ul > r)
 		return 0;
 	if (l <= ul && ur <= r)
 		return t[u];
 	int um = ul + ur >> 1;
 	return max(get(u + u, ul, um, l, r), get(u + u + 1, um + 1, ur, l, r));
}     

int main() { 
	ios_base :: sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n >> q;
  int g[q + 1];
  a.resize(n + 1);
  t.resize(4 * n);
  for (int i = 1; i <= n; i++)
  	cin >> a[i];
  for (int i = 1; i <= q; i++) {
   	int l, r, k;
   	cin >> l >> r >> k;
   	all.pb({r, l, k, i});
  }
  sort(all(all), cmp);
  stack<pair<int, int>> s;
  for (int i = 1; i <= n; i++) {
   	while (!s.empty() && s.top().fr <= a[i])
   		s.pop();	
   	if (!s.empty()) pos[i] = s.top().sc;
   	s.push({a[i], i});
  }
  int k = 0;
  for (int i = 1; i <= n; i++) {
		if (pos[i] != 0) {
			//cout << pos[i] << endl;
			update(1, 1, n, pos[i], a[i] + a[pos[i]]);
		}
		while (k < q && all[k].r == i) {
		 	int l = all[k].l;
		 	int r = all[k].r;
		 	int val = all[k].k;
		 	int id = all[k].pos;
		 	int ans = get(1, 1, n, l, r);
		 	// << l << " " << r << " " << ans << endl;
		 	if (ans > val) g[id] = 0;
		 	else g[id] = 1;
		 	k++;
		}
  }
  for (int i = 1; i <= q; i++)
  	cout << g[i] << "\n";
	return 0;
}

Compilation message

sortbooks.cpp: In function 'void update(int, int, int, int, int)':
sortbooks.cpp:54:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int m = l + r >> 1;
           ~~^~~
sortbooks.cpp: In function 'int get(int, int, int, int, int)':
sortbooks.cpp:65:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   int um = ul + ur >> 1;
            ~~~^~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:109:3: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   for (int i = 1; i <= q; i++)
   ^~~
sortbooks.cpp:111:2: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
  return 0;
  ^~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 8 ms 768 KB Output is correct
14 Correct 11 ms 896 KB Output is correct
15 Correct 10 ms 892 KB Output is correct
16 Correct 9 ms 892 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 8 ms 768 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1510 ms 77364 KB Output is correct
2 Correct 1463 ms 78368 KB Output is correct
3 Correct 1483 ms 78228 KB Output is correct
4 Correct 1453 ms 78368 KB Output is correct
5 Correct 1225 ms 74540 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 147 ms 6996 KB Output is correct
2 Correct 110 ms 6996 KB Output is correct
3 Correct 95 ms 6576 KB Output is correct
4 Correct 102 ms 6612 KB Output is correct
5 Correct 100 ms 6636 KB Output is correct
6 Correct 85 ms 6508 KB Output is correct
7 Correct 87 ms 6460 KB Output is correct
8 Correct 99 ms 6512 KB Output is correct
9 Correct 51 ms 4072 KB Output is correct
10 Correct 85 ms 6508 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 8 ms 768 KB Output is correct
14 Correct 11 ms 896 KB Output is correct
15 Correct 10 ms 892 KB Output is correct
16 Correct 9 ms 892 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 8 ms 768 KB Output is correct
19 Correct 273 ms 16132 KB Output is correct
20 Correct 249 ms 16112 KB Output is correct
21 Correct 247 ms 15960 KB Output is correct
22 Correct 234 ms 15968 KB Output is correct
23 Correct 226 ms 15948 KB Output is correct
24 Correct 208 ms 15080 KB Output is correct
25 Correct 205 ms 15056 KB Output is correct
26 Correct 211 ms 15204 KB Output is correct
27 Correct 211 ms 15208 KB Output is correct
28 Correct 237 ms 15204 KB Output is correct
29 Correct 215 ms 15332 KB Output is correct
30 Correct 214 ms 15336 KB Output is correct
31 Correct 226 ms 15332 KB Output is correct
32 Correct 227 ms 15308 KB Output is correct
33 Correct 220 ms 15348 KB Output is correct
34 Correct 207 ms 14948 KB Output is correct
35 Correct 209 ms 14924 KB Output is correct
36 Correct 216 ms 14768 KB Output is correct
37 Correct 210 ms 14780 KB Output is correct
38 Correct 214 ms 14948 KB Output is correct
39 Correct 222 ms 14156 KB Output is correct
40 Correct 170 ms 12004 KB Output is correct
41 Correct 223 ms 14056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 384 KB Output is correct
2 Correct 5 ms 384 KB Output is correct
3 Correct 5 ms 384 KB Output is correct
4 Correct 5 ms 384 KB Output is correct
5 Correct 5 ms 384 KB Output is correct
6 Correct 5 ms 384 KB Output is correct
7 Correct 5 ms 384 KB Output is correct
8 Correct 5 ms 384 KB Output is correct
9 Correct 5 ms 384 KB Output is correct
10 Correct 5 ms 384 KB Output is correct
11 Correct 7 ms 640 KB Output is correct
12 Correct 8 ms 640 KB Output is correct
13 Correct 8 ms 768 KB Output is correct
14 Correct 11 ms 896 KB Output is correct
15 Correct 10 ms 892 KB Output is correct
16 Correct 9 ms 892 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 8 ms 768 KB Output is correct
19 Correct 1510 ms 77364 KB Output is correct
20 Correct 1463 ms 78368 KB Output is correct
21 Correct 1483 ms 78228 KB Output is correct
22 Correct 1453 ms 78368 KB Output is correct
23 Correct 1225 ms 74540 KB Output is correct
24 Correct 147 ms 6996 KB Output is correct
25 Correct 110 ms 6996 KB Output is correct
26 Correct 95 ms 6576 KB Output is correct
27 Correct 102 ms 6612 KB Output is correct
28 Correct 100 ms 6636 KB Output is correct
29 Correct 85 ms 6508 KB Output is correct
30 Correct 87 ms 6460 KB Output is correct
31 Correct 99 ms 6512 KB Output is correct
32 Correct 51 ms 4072 KB Output is correct
33 Correct 85 ms 6508 KB Output is correct
34 Correct 273 ms 16132 KB Output is correct
35 Correct 249 ms 16112 KB Output is correct
36 Correct 247 ms 15960 KB Output is correct
37 Correct 234 ms 15968 KB Output is correct
38 Correct 226 ms 15948 KB Output is correct
39 Correct 208 ms 15080 KB Output is correct
40 Correct 205 ms 15056 KB Output is correct
41 Correct 211 ms 15204 KB Output is correct
42 Correct 211 ms 15208 KB Output is correct
43 Correct 237 ms 15204 KB Output is correct
44 Correct 215 ms 15332 KB Output is correct
45 Correct 214 ms 15336 KB Output is correct
46 Correct 226 ms 15332 KB Output is correct
47 Correct 227 ms 15308 KB Output is correct
48 Correct 220 ms 15348 KB Output is correct
49 Correct 207 ms 14948 KB Output is correct
50 Correct 209 ms 14924 KB Output is correct
51 Correct 216 ms 14768 KB Output is correct
52 Correct 210 ms 14780 KB Output is correct
53 Correct 214 ms 14948 KB Output is correct
54 Correct 222 ms 14156 KB Output is correct
55 Correct 170 ms 12004 KB Output is correct
56 Correct 223 ms 14056 KB Output is correct
57 Correct 1510 ms 79144 KB Output is correct
58 Correct 1512 ms 79136 KB Output is correct
59 Correct 1452 ms 79036 KB Output is correct
60 Correct 1417 ms 79060 KB Output is correct
61 Correct 1408 ms 79072 KB Output is correct
62 Correct 1352 ms 79188 KB Output is correct
63 Correct 1030 ms 73408 KB Output is correct
64 Correct 1062 ms 73288 KB Output is correct
65 Correct 1251 ms 75128 KB Output is correct
66 Correct 1280 ms 75256 KB Output is correct
67 Correct 1149 ms 75104 KB Output is correct
68 Correct 1172 ms 75272 KB Output is correct
69 Correct 1132 ms 75204 KB Output is correct
70 Correct 1262 ms 75300 KB Output is correct
71 Correct 1249 ms 75252 KB Output is correct
72 Correct 1200 ms 75192 KB Output is correct
73 Correct 1022 ms 71728 KB Output is correct
74 Correct 1075 ms 72852 KB Output is correct
75 Correct 1041 ms 71780 KB Output is correct
76 Correct 1073 ms 71856 KB Output is correct
77 Correct 1008 ms 71864 KB Output is correct
78 Correct 1129 ms 70388 KB Output is correct
79 Correct 830 ms 55528 KB Output is correct
80 Correct 1080 ms 69036 KB Output is correct