# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
139527 |
2019-07-31T23:44:46 Z |
dcordb |
Wall (IOI14_wall) |
C++11 |
|
3000 ms |
102492 KB |
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
typedef pair <char, int> op;
const int MAX = 1e6 + 5;
vector <op> lazy[4 * MAX];
int a[MAX];
vector <op> concat(const vector <op> &a, const vector <op> &b) {
vector <op> v;
for(auto o : a) v.push_back(o);
for(auto o : b) v.push_back(o);
return v;
}
vector <op> reduce(const op &a, const op &b) {
int x = a.second;
int y = b.second;
if(b.first == 's')
return {b};
if(a.first == 's') {
if(b.first == 'm') {
if(x <= y)
return {op('s', x)};
return {op('s', y)};
}
else {
assert(b.first == 'M');
if(x <= y)
return {op('s', y)};
return {op('s', x)};
}
}
if(a.first == 'm' && b.first == 'm') {
if(x <= y)
return {a};
return {b};
}
if(a.first == 'M' && b.first == 'M') {
if(x <= y)
return {b};
return {a};
}
if(a.first == 'm' && b.first == 'M') {
if(x <= y)
return {op('s', y)};
return {a, b};
}
assert(a.first == 'M' && b.first == 'm');
if(x <= y)
return {a, b};
return {op('s', y)};
}
vector <op> tryReduce(const vector <op> &v) {
for(int i = 0; i < (int) v.size() - 1; i++) {
auto r = reduce(v[i], v[i + 1]);
if((int) r.size() == 1) {
vector <op> aux;
for(int j = 0; j < i; j++)
aux.push_back(v[j]);
aux.push_back(r[0]);
for(int j = i + 2; j < (int) v.size(); j++)
aux.push_back(v[j]);
return aux;
}
}
return {};
}
vector <op> reduce(const vector <op> &v) {
assert((int) v.size() <= 4);
if((int) v.size() == 1)
return v;
vector <op> r = tryReduce(v);
if(r.empty()) { //no pudo reducir
if((int) v.size() == 2)
return v;
r = v;
swap(r[0], r[1]);
return reduce(r);
}
return reduce(r);
}
void build(int x, int st, int nd) {
lazy[x].push_back(op('M', 0));
if(st == nd) return;
int mid = (st + nd) >> 1;
build(2 * x, st, mid);
build(2 * x + 1, mid + 1, nd);
}
void prop(int x, int st, int nd) {
if(st == nd) {
auto r = reduce(concat({op('s', a[st])}, lazy[x]));
assert((int) r.size() == 1);
a[st] = r[0].second;
}
else {
lazy[2 * x] = reduce(concat(lazy[2 * x], lazy[x]));
lazy[2 * x + 1] = reduce(concat(lazy[2 * x + 1], lazy[x]));
}
lazy[x] = {op('M', 0)};
}
void upd(int x, int st, int nd, int a, int b, const op &o) {
prop(x, st, nd);
if(st > b || nd < a)
return;
if(st >= a && nd <= b) {
lazy[x] = {o};
prop(x, st, nd);
return;
}
int mid = (st + nd) >> 1;
upd(2 * x, st, mid, a, b, o);
upd(2 * x + 1, mid + 1, nd, a, b, o);
}
void buildWall(int n, int m, int operation[], int l[], int r[], int h[], int ans[]) {
build(1, 0, n - 1);
for(int i = 0; i < m; i++) {
if(operation[i] == 1)
upd(1, 0, n - 1, l[i], r[i], op('M', h[i]));
else upd(1, 0, n - 1, l[i], r[i], op('m', h[i]));
}
for(int i = 0; i < n; i++) {
upd(1, 0, n - 1, i, i, op('M', 0));
ans[i] = a[i];
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
91 ms |
94328 KB |
Output is correct |
2 |
Correct |
109 ms |
94456 KB |
Output is correct |
3 |
Correct |
144 ms |
94328 KB |
Output is correct |
4 |
Correct |
390 ms |
95196 KB |
Output is correct |
5 |
Correct |
343 ms |
95164 KB |
Output is correct |
6 |
Correct |
336 ms |
95224 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
89 ms |
94272 KB |
Output is correct |
2 |
Correct |
517 ms |
102424 KB |
Output is correct |
3 |
Execution timed out |
3047 ms |
99036 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
88 ms |
94200 KB |
Output is correct |
2 |
Correct |
93 ms |
94472 KB |
Output is correct |
3 |
Correct |
124 ms |
94344 KB |
Output is correct |
4 |
Correct |
380 ms |
95224 KB |
Output is correct |
5 |
Correct |
341 ms |
95200 KB |
Output is correct |
6 |
Correct |
340 ms |
95272 KB |
Output is correct |
7 |
Correct |
90 ms |
94368 KB |
Output is correct |
8 |
Correct |
525 ms |
102396 KB |
Output is correct |
9 |
Execution timed out |
3043 ms |
99064 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
87 ms |
94200 KB |
Output is correct |
2 |
Correct |
93 ms |
94420 KB |
Output is correct |
3 |
Correct |
125 ms |
94420 KB |
Output is correct |
4 |
Correct |
380 ms |
95176 KB |
Output is correct |
5 |
Correct |
336 ms |
95236 KB |
Output is correct |
6 |
Correct |
340 ms |
95352 KB |
Output is correct |
7 |
Correct |
89 ms |
94328 KB |
Output is correct |
8 |
Correct |
520 ms |
102492 KB |
Output is correct |
9 |
Execution timed out |
3043 ms |
99064 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |