답안 #587476

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
587476 2022-07-01T23:59:22 Z NekoRolly RMQ (NOI17_rmq) C++17
100 / 100
55 ms 9824 KB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5+4;

struct St{
	int n,t[N<<1];

	void up(int l,int r,int val){
		for (l+=n, r+=n; l<r; l>>=1, r>>=1){
			if (l&1) t[l] = max(t[l], val), l++;
			if (r&1) r--, t[r] = max(t[r], val);
		}
	}

	int que(int i){ int ans = t[i+=n];
		for (; i>>=1; ) ans = max(ans, t[i]);
		return ans;
	}
} d1;

int n,q;
int a[N],p[N];
int L[N],R[N];
set<int> d2;
vector<int> d3[N];

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	
	cin >> n >> q; d1.n = n;

	for (int i=0; i<n; i++) R[i] = n-1, p[i] = -1;

	for (int i=0,l,r,x; i<q; i++){ cin >> l >> r >> x;
		d1.up(l, r+1, x);
		L[x] = max(L[x], l), R[x] = min(R[x], r);
	}

	for (int i=0; i<n; i++) d3[d1.que(i)].push_back(i);

	for (int i=0; i<n; i++){ int pos = -1;
		for (int j : d3[i]) d2.insert(j);
		auto it = d2.lower_bound(L[i]);
		if (it != d2.end() && *it <= R[i]) pos = *it;
		if (pos == -1){
			for (int i=0; i<n; i++) p[i] = -1;
			break;
		}
		p[pos] = i; d2.erase(pos);
	}

	for (int i=0; i<n; i++) cout << p[i] << " "; cout << "\n";

    return 0;
}

Compilation message

rmq.cpp: In function 'int main()':
rmq.cpp:53:2: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   53 |  for (int i=0; i<n; i++) cout << p[i] << " "; cout << "\n";
      |  ^~~
rmq.cpp:53:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   53 |  for (int i=0; i<n; i++) cout << p[i] << " "; cout << "\n";
      |                                               ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2664 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 2644 KB Output is correct
2 Correct 1 ms 2644 KB Output is correct
3 Correct 1 ms 2644 KB Output is correct
4 Correct 1 ms 2644 KB Output is correct
5 Correct 1 ms 2644 KB Output is correct
6 Correct 1 ms 2644 KB Output is correct
7 Correct 1 ms 2644 KB Output is correct
8 Correct 1 ms 2644 KB Output is correct
9 Correct 1 ms 2644 KB Output is correct
10 Correct 1 ms 2644 KB Output is correct
11 Correct 1 ms 2644 KB Output is correct
12 Correct 2 ms 2644 KB Output is correct
13 Correct 2 ms 2644 KB Output is correct
14 Correct 2 ms 2644 KB Output is correct
15 Correct 2 ms 2644 KB Output is correct
16 Correct 2 ms 2644 KB Output is correct
17 Correct 2 ms 2644 KB Output is correct
18 Correct 2 ms 2644 KB Output is correct
19 Correct 2 ms 2644 KB Output is correct
20 Correct 1 ms 2644 KB Output is correct
21 Correct 1 ms 2644 KB Output is correct
22 Correct 1 ms 2644 KB Output is correct
23 Correct 2 ms 2644 KB Output is correct
24 Correct 2 ms 2664 KB Output is correct
25 Correct 1 ms 2644 KB Output is correct
26 Correct 2 ms 2644 KB Output is correct
27 Correct 51 ms 7860 KB Output is correct
28 Correct 54 ms 9452 KB Output is correct
29 Correct 46 ms 9076 KB Output is correct
30 Correct 55 ms 9824 KB Output is correct
31 Correct 44 ms 8160 KB Output is correct
32 Correct 51 ms 8072 KB Output is correct
33 Correct 30 ms 8080 KB Output is correct
34 Correct 18 ms 6732 KB Output is correct
35 Correct 32 ms 9588 KB Output is correct
36 Correct 31 ms 6036 KB Output is correct
37 Correct 39 ms 6408 KB Output is correct
38 Correct 8 ms 3836 KB Output is correct
39 Correct 33 ms 5788 KB Output is correct
40 Correct 1 ms 2644 KB Output is correct
41 Correct 1 ms 2644 KB Output is correct