답안 #236391

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
236391 2020-06-01T18:19:26 Z _7_7_ Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1928 ms 108444 KB
#include <bits/stdc++.h>                                           
 
//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")
 
 
#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first
 
 
using namespace std;
 
 
typedef pair < long long, long long > pll;    
typedef pair < int, int > pii;
typedef unsigned long long ull;         
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;  
typedef long long ll;  
typedef double db;                             
 
 
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const int inf = 1e9, maxn = 4e5 + 148, mod = 1e9 + 7, N = 1e6 + 11;
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

int n, m, a[N], l[N], r[N], k[N], b[N], t[N << 2], res[N];
vi g[N];
stack < int > s;

void update (int pos, int x, int v = 1, int tl = 1, int tr = n) {
    t[v] = max(t[v], x);
	if (tl == tr)  
		return;

	int tm = (tl + tr) >> 1;
	if (pos <= tm)		
		update(pos, x, v << 1, tl, tm);
	else
		update(pos, x, v << 1 | 1, tm + 1, tr);
	t[v] = max(t[v << 1], t[v << 1 | 1]);
}

int get (int l, int r, int v = 1, int tl = 1, int tr = n) {
	if (l > r || l > tr || tl > r)
		return 0;

	if (l <= tl && tr <= r)
		return t[v];

	int tm = (tl + tr) >> 1;
	return max(get(l, r, v << 1, tl, tm), get(l, r, v << 1 | 1, tm + 1, tr));
}


main () {
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; ++i)
		scanf("%d", &a[i]);
	
	for (int i = 1; i <= n; ++i) {
		while (sz(s) && a[s.top()] <= a[i])
			s.pop();

		if (sz(s))
			b[i] = s.top();
		s.push(i);
	}

	for (int i = 1; i <= m; ++i) {
		scanf("%d%d%d", &l[i], &r[i], &k[i]);
		g[r[i]].pb(i);
	}

//	for (int i = 1; i <= n; ++i)
//		cerr << i << ' ' << b[i] << endl;

	for (int r = 1; r <= n; ++r) {
		if (b[r])
			update(b[r], a[b[r]] + a[r]);
		for (auto i : g[r])
			res[i] = (get(l[i], r) <= k[i]);
	}


	for (int i = 1; i <= m; ++i)
		printf("%d\n", res[i]);	

		

}

Compilation message

sortbooks.cpp:69:7: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main () {
       ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:70:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d", &a[i]);
   ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:84:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d%d", &l[i], &r[i], &k[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23936 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 19 ms 23936 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 20 ms 23808 KB Output is correct
6 Correct 19 ms 23936 KB Output is correct
7 Correct 19 ms 23936 KB Output is correct
8 Correct 18 ms 23936 KB Output is correct
9 Correct 20 ms 23936 KB Output is correct
10 Correct 19 ms 23936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23936 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 19 ms 23936 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 20 ms 23808 KB Output is correct
6 Correct 19 ms 23936 KB Output is correct
7 Correct 19 ms 23936 KB Output is correct
8 Correct 18 ms 23936 KB Output is correct
9 Correct 20 ms 23936 KB Output is correct
10 Correct 19 ms 23936 KB Output is correct
11 Correct 23 ms 24064 KB Output is correct
12 Correct 22 ms 24196 KB Output is correct
13 Correct 22 ms 24192 KB Output is correct
14 Correct 24 ms 24320 KB Output is correct
15 Correct 31 ms 24320 KB Output is correct
16 Correct 22 ms 24192 KB Output is correct
17 Correct 23 ms 24192 KB Output is correct
18 Correct 22 ms 24192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1928 ms 107456 KB Output is correct
2 Correct 1894 ms 108364 KB Output is correct
3 Correct 1879 ms 108444 KB Output is correct
4 Correct 1882 ms 108444 KB Output is correct
5 Correct 1528 ms 96248 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 134 ms 31096 KB Output is correct
2 Correct 123 ms 30200 KB Output is correct
3 Correct 115 ms 29432 KB Output is correct
4 Correct 120 ms 29624 KB Output is correct
5 Correct 117 ms 29560 KB Output is correct
6 Correct 99 ms 28536 KB Output is correct
7 Correct 99 ms 28664 KB Output is correct
8 Correct 125 ms 29544 KB Output is correct
9 Correct 65 ms 27508 KB Output is correct
10 Correct 109 ms 29512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23936 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 19 ms 23936 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 20 ms 23808 KB Output is correct
6 Correct 19 ms 23936 KB Output is correct
7 Correct 19 ms 23936 KB Output is correct
8 Correct 18 ms 23936 KB Output is correct
9 Correct 20 ms 23936 KB Output is correct
10 Correct 19 ms 23936 KB Output is correct
11 Correct 23 ms 24064 KB Output is correct
12 Correct 22 ms 24196 KB Output is correct
13 Correct 22 ms 24192 KB Output is correct
14 Correct 24 ms 24320 KB Output is correct
15 Correct 31 ms 24320 KB Output is correct
16 Correct 22 ms 24192 KB Output is correct
17 Correct 23 ms 24192 KB Output is correct
18 Correct 22 ms 24192 KB Output is correct
19 Correct 306 ms 40824 KB Output is correct
20 Correct 307 ms 40824 KB Output is correct
21 Correct 278 ms 39056 KB Output is correct
22 Correct 255 ms 39032 KB Output is correct
23 Correct 257 ms 39160 KB Output is correct
24 Correct 237 ms 35960 KB Output is correct
25 Correct 222 ms 35856 KB Output is correct
26 Correct 253 ms 36856 KB Output is correct
27 Correct 262 ms 36728 KB Output is correct
28 Correct 255 ms 37112 KB Output is correct
29 Correct 268 ms 38244 KB Output is correct
30 Correct 268 ms 38008 KB Output is correct
31 Correct 288 ms 38008 KB Output is correct
32 Correct 267 ms 38028 KB Output is correct
33 Correct 262 ms 38008 KB Output is correct
34 Correct 219 ms 35544 KB Output is correct
35 Correct 213 ms 35576 KB Output is correct
36 Correct 198 ms 35448 KB Output is correct
37 Correct 201 ms 35468 KB Output is correct
38 Correct 212 ms 35576 KB Output is correct
39 Correct 233 ms 37236 KB Output is correct
40 Correct 181 ms 35180 KB Output is correct
41 Correct 231 ms 36464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 23936 KB Output is correct
2 Correct 18 ms 23808 KB Output is correct
3 Correct 19 ms 23936 KB Output is correct
4 Correct 18 ms 23808 KB Output is correct
5 Correct 20 ms 23808 KB Output is correct
6 Correct 19 ms 23936 KB Output is correct
7 Correct 19 ms 23936 KB Output is correct
8 Correct 18 ms 23936 KB Output is correct
9 Correct 20 ms 23936 KB Output is correct
10 Correct 19 ms 23936 KB Output is correct
11 Correct 23 ms 24064 KB Output is correct
12 Correct 22 ms 24196 KB Output is correct
13 Correct 22 ms 24192 KB Output is correct
14 Correct 24 ms 24320 KB Output is correct
15 Correct 31 ms 24320 KB Output is correct
16 Correct 22 ms 24192 KB Output is correct
17 Correct 23 ms 24192 KB Output is correct
18 Correct 22 ms 24192 KB Output is correct
19 Correct 1928 ms 107456 KB Output is correct
20 Correct 1894 ms 108364 KB Output is correct
21 Correct 1879 ms 108444 KB Output is correct
22 Correct 1882 ms 108444 KB Output is correct
23 Correct 1528 ms 96248 KB Output is correct
24 Correct 134 ms 31096 KB Output is correct
25 Correct 123 ms 30200 KB Output is correct
26 Correct 115 ms 29432 KB Output is correct
27 Correct 120 ms 29624 KB Output is correct
28 Correct 117 ms 29560 KB Output is correct
29 Correct 99 ms 28536 KB Output is correct
30 Correct 99 ms 28664 KB Output is correct
31 Correct 125 ms 29544 KB Output is correct
32 Correct 65 ms 27508 KB Output is correct
33 Correct 109 ms 29512 KB Output is correct
34 Correct 306 ms 40824 KB Output is correct
35 Correct 307 ms 40824 KB Output is correct
36 Correct 278 ms 39056 KB Output is correct
37 Correct 255 ms 39032 KB Output is correct
38 Correct 257 ms 39160 KB Output is correct
39 Correct 237 ms 35960 KB Output is correct
40 Correct 222 ms 35856 KB Output is correct
41 Correct 253 ms 36856 KB Output is correct
42 Correct 262 ms 36728 KB Output is correct
43 Correct 255 ms 37112 KB Output is correct
44 Correct 268 ms 38244 KB Output is correct
45 Correct 268 ms 38008 KB Output is correct
46 Correct 288 ms 38008 KB Output is correct
47 Correct 267 ms 38028 KB Output is correct
48 Correct 262 ms 38008 KB Output is correct
49 Correct 219 ms 35544 KB Output is correct
50 Correct 213 ms 35576 KB Output is correct
51 Correct 198 ms 35448 KB Output is correct
52 Correct 201 ms 35468 KB Output is correct
53 Correct 212 ms 35576 KB Output is correct
54 Correct 233 ms 37236 KB Output is correct
55 Correct 181 ms 35180 KB Output is correct
56 Correct 231 ms 36464 KB Output is correct
57 Correct 1876 ms 81224 KB Output is correct
58 Correct 1857 ms 81080 KB Output is correct
59 Correct 1745 ms 77088 KB Output is correct
60 Correct 1741 ms 76972 KB Output is correct
61 Correct 1741 ms 77144 KB Output is correct
62 Correct 1729 ms 77044 KB Output is correct
63 Correct 1144 ms 58616 KB Output is correct
64 Correct 1122 ms 58616 KB Output is correct
65 Correct 1467 ms 64248 KB Output is correct
66 Correct 1415 ms 64248 KB Output is correct
67 Correct 1454 ms 64688 KB Output is correct
68 Correct 1504 ms 68984 KB Output is correct
69 Correct 1554 ms 69112 KB Output is correct
70 Correct 1504 ms 68448 KB Output is correct
71 Correct 1504 ms 68272 KB Output is correct
72 Correct 1474 ms 68216 KB Output is correct
73 Correct 1033 ms 61008 KB Output is correct
74 Correct 1056 ms 82464 KB Output is correct
75 Correct 1039 ms 61536 KB Output is correct
76 Correct 1050 ms 57976 KB Output is correct
77 Correct 1051 ms 57800 KB Output is correct
78 Correct 1338 ms 70660 KB Output is correct
79 Correct 961 ms 62472 KB Output is correct
80 Correct 1309 ms 69636 KB Output is correct