# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
891368 |
2023-12-22T19:54:47 Z |
stefanneagu |
RMQ (NOI17_rmq) |
C++17 |
|
97 ms |
14148 KB |
#include <bits/stdc++.h>
using namespace std;
const int nmax = 1e5 + 1;
struct str {
int a, b, val;
const bool operator < (str ult) const {
return val < ult.val;
}
} v[nmax];
int aint[4 * nmax], lz[4 * nmax], rmq[nmax][20], used[nmax], viz[nmax];
int rmquery(int a, int b) {
int lg = (int) log2(b - a + 1);
return min(rmq[a][lg], rmq[b - (1 << lg) + 1][lg]);
}
void lazy(int nod, int st, int dr) {
aint[nod] = lz[nod];
if(st != dr) {
lz[nod << 1] = lz[nod];
lz[nod << 1|1] = lz[nod];
}
lz[nod] = 0;
}
void update(int nod, int st, int dr, int l, int r, int val) {
if(lz[nod]) {
lazy(nod, st, dr);
}
if(st > r || dr < l) {
return;
}
if(l <= st && dr <= r) {
lz[nod] = val;
lazy(nod, st, dr);
return;
}
int mid = (st + dr) / 2;
update(nod << 1, st, mid, l, r, val);
update(nod << 1|1, mid + 1, dr, l, r, val);
}
int query(int nod, int st, int dr, int poz) {
if(lz[nod]) {
lazy(nod, st, dr);
}
if(st == dr) {
return aint[nod];
}
int mid = (st + dr) / 2;
if(poz <= mid) {
return query(nod << 1, st, mid, poz);
} else {
return query(nod << 1|1, mid + 1, dr, poz);
}
}
int check(int n, int q, vector<int> &nou) {
vector<vector<int>> r(n + 1, vector<int>((int) log2(n) + 4));
for(int i = 1; i <= n; i ++) {
r[i][0] = nou[i];
}
for(int j = 1; (1 << j) <= n; j ++) {
for(int i = 1; i + (1 << j) - 1 <= n; i ++) {
r[i][j] = min(r[i][j - 1], r[i + (1 << (j - 1))][j - 1]);
}
}
for(int i = 1; i <= q; i ++) {
int dist = (v[i].b - v[i].a + 1);
dist = (int) log2(dist);
int curr = min(r[v[i].a][dist], r[v[i].b - (1 << dist) + 1][dist]);
if(curr != v[i].val) {
return 0;
}
}
return 1;
}
void bulan_pe_subtask(int n, int q, vector<int> &nou) {
for(int i = 1; i <= n; i ++) {
used[nou[i]] ++;
}
vector<int> un;
for(int i = 0; i < n; i ++) {
if(!used[i]) {
un.push_back(i);
}
}
for(auto nr : un) {
bool ok = 0;
for(int i = 1; i <= n; i ++) {
if(!viz[i]) {
int ult = nou[i];
nou[i] = nr;
if(check(n, q, nou)) {
viz[i] = 1;
ok = 1;
break;
} else {
nou[i] = ult;
}
}
}
if(!ok) {
for(int i = 1; i <= n; i ++) {
cout << "-1 ";
}
return;
}
}
for(int i = 1; i <= n; i ++) {
cout << nou[i] << " ";
}
}
int main() {
int n, q;
cin >> n >> q;
for(int i = 1; i <= q; i ++) {
int a, b, val;
cin >> a >> b >> val;
a ++;
b ++;
v[i].a = a, v[i].b = b, v[i].val = val;
}
sort(v + 1, v + q + 1);
for(int i = 1; i <= q; i ++) {
update(1, 1, n, v[i].a, v[i].b, v[i].val);
}
vector<int> nou(n + 1);
for(int i = 1; i <= n; i ++) {
nou[i] = query(1, 1, n, i);
rmq[i][0] = nou[i];
}
for(int j = 1; (1 << j) <= n; j ++) {
for(int i = 1; i + (1 << j) - 1 <= n; i ++) {
rmq[i][j] = min(rmq[i][j - 1], rmq[i + (1 << (j - 1))][j - 1]);
}
}
if(n <= 25) {
bulan_pe_subtask(n, q, nou);
return 0;
}
for(int i = 1; i <= q; i ++) {
if(rmquery(v[i].a, v[i].b) != v[i].val) {
for(int j = 1; j <= n; j ++) {
cout << "-1 ";
}
return 0;
}
}
for(int i = 1; i <= n; i ++) {
cout << nou[i] << " ";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
13 |
Partially correct |
2 ms |
4444 KB |
Output is partially correct |
14 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
15 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
16 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
17 |
Partially correct |
2 ms |
4444 KB |
Output is partially correct |
18 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
19 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
20 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4660 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
2 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4444 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
1 ms |
4444 KB |
Output is correct |
8 |
Correct |
1 ms |
4444 KB |
Output is correct |
9 |
Correct |
1 ms |
4440 KB |
Output is correct |
10 |
Correct |
1 ms |
4444 KB |
Output is correct |
11 |
Correct |
1 ms |
4444 KB |
Output is correct |
12 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
13 |
Partially correct |
2 ms |
4444 KB |
Output is partially correct |
14 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
15 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
16 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
17 |
Partially correct |
2 ms |
4444 KB |
Output is partially correct |
18 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
19 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
20 |
Partially correct |
1 ms |
4444 KB |
Output is partially correct |
21 |
Correct |
1 ms |
4444 KB |
Output is correct |
22 |
Correct |
2 ms |
4660 KB |
Output is correct |
23 |
Correct |
1 ms |
4444 KB |
Output is correct |
24 |
Correct |
2 ms |
4444 KB |
Output is correct |
25 |
Correct |
1 ms |
4444 KB |
Output is correct |
26 |
Correct |
1 ms |
4444 KB |
Output is correct |
27 |
Partially correct |
97 ms |
12184 KB |
Output is partially correct |
28 |
Partially correct |
82 ms |
13692 KB |
Output is partially correct |
29 |
Partially correct |
67 ms |
13388 KB |
Output is partially correct |
30 |
Partially correct |
92 ms |
14148 KB |
Output is partially correct |
31 |
Partially correct |
74 ms |
10756 KB |
Output is partially correct |
32 |
Partially correct |
89 ms |
11600 KB |
Output is partially correct |
33 |
Partially correct |
12 ms |
12380 KB |
Output is partially correct |
34 |
Partially correct |
9 ms |
9820 KB |
Output is partially correct |
35 |
Partially correct |
21 ms |
12624 KB |
Output is partially correct |
36 |
Correct |
62 ms |
13392 KB |
Output is correct |
37 |
Correct |
88 ms |
13908 KB |
Output is correct |
38 |
Correct |
8 ms |
10332 KB |
Output is correct |
39 |
Correct |
72 ms |
13732 KB |
Output is correct |
40 |
Correct |
1 ms |
4696 KB |
Output is correct |
41 |
Correct |
1 ms |
4444 KB |
Output is correct |