# |
제출 시각 |
아이디 |
문제 |
언어 |
결과 |
실행 시간 |
메모리 |
139554 |
2019-08-01T02:48:56 Z |
dcordb |
벽 (IOI14_wall) |
C++11 |
|
3000 ms |
103924 KB |
#include "wall.h"
#include <bits/stdc++.h>
using namespace std;
const int
MAX = 1e6 + 5,
INF = 1e6;
vector <int> lazy[4 * MAX];
int a[MAX];
vector <int> concat(const vector <int> &a, const vector <int> &b) {
vector <int> v;
for(auto o : a) v.push_back(o);
for(auto o : b) v.push_back(o);
return v;
}
int reduce(const int &a, const int &b, bool &ok) {
int x = abs(a);
int y = abs(b);
if(a < 0 && b < 0)
return (x <= y) ? a : b;
if(a >= 0 && b >= 0)
return (x <= y) ? b : a;
ok = false;
return 0;
}
vector <int> tryReduce(vector <int> v) {
for(int i = 0; i < (int) v.size() - 1; i++) {
bool ok = true;
int r = reduce(v[i], v[i + 1], ok);
if(ok) {
vector <int> aux;
for(int j = 0; j < i; j++)
aux.push_back(v[j]);
aux.push_back(r);
for(int j = i + 2; j < (int) v.size(); j++)
aux.push_back(v[j]);
return aux;
}
}
return {};
}
int sgn(int x) { return (x >= 0) ? +1 : -1; }
void transform(int &a, int &b) {
assert(sgn(a) != sgn(b));
int x = abs(a);
int y = abs(b);
if(a < 0 && b >= 0) {
if(x <= y) {
a = INF;
b *= -1;
}
else swap(a, b);
}
else {
assert(b < 0);
if(x <= y)
swap(a, b);
else {
a = -1;
b *= -1;
}
}
}
vector <int> reduce(vector <int> v) {
if((int) v.size() > 4) {
printf("sz = %d\n", (int) v.size());
for(int o : v)
printf("%d ", o);
printf("\n");
}
assert((int) v.size() <= 4);
while((int) v.size() > 1) {
auto r = tryReduce(v);
if(r.empty()) {
if((int) v.size() == 2)
break;
transform(v[0], v[1]);
}
else v = r;
}
assert((int) v.size() <= 2);
return v;
}
void build(int x, int st, int nd) {
lazy[x] = {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) {
for(auto o : lazy[x]) {
if(o >= 0)
a[st] = max(a[st], o);
else a[st] = min(a[st], -o);
}
}
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] = {0};
}
void upd(int x, int st, int nd, int a, int b, const int &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++) {
int height = h[i] + 1;
if(operation[i] == 1)
upd(1, 0, n - 1, l[i], r[i], height);
else upd(1, 0, n - 1, l[i], r[i], -height);
}
for(int i = 0; i < n; i++) {
upd(1, 0, n - 1, i, i, 0);
ans[i] = max(0, a[i] - 1);
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
91 ms |
94328 KB |
Output is correct |
2 |
Correct |
92 ms |
94456 KB |
Output is correct |
3 |
Correct |
129 ms |
94328 KB |
Output is correct |
4 |
Correct |
433 ms |
95224 KB |
Output is correct |
5 |
Correct |
327 ms |
95264 KB |
Output is correct |
6 |
Correct |
328 ms |
95224 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
89 ms |
94200 KB |
Output is correct |
2 |
Correct |
275 ms |
103872 KB |
Output is correct |
3 |
Execution timed out |
3060 ms |
100520 KB |
Time limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
94200 KB |
Output is correct |
2 |
Correct |
103 ms |
94436 KB |
Output is correct |
3 |
Correct |
129 ms |
94328 KB |
Output is correct |
4 |
Correct |
435 ms |
95172 KB |
Output is correct |
5 |
Correct |
329 ms |
95232 KB |
Output is correct |
6 |
Correct |
329 ms |
95196 KB |
Output is correct |
7 |
Correct |
90 ms |
94200 KB |
Output is correct |
8 |
Correct |
274 ms |
103924 KB |
Output is correct |
9 |
Execution timed out |
3044 ms |
100600 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
90 ms |
94200 KB |
Output is correct |
2 |
Correct |
96 ms |
94396 KB |
Output is correct |
3 |
Correct |
156 ms |
94456 KB |
Output is correct |
4 |
Correct |
451 ms |
95196 KB |
Output is correct |
5 |
Correct |
330 ms |
95280 KB |
Output is correct |
6 |
Correct |
329 ms |
95224 KB |
Output is correct |
7 |
Correct |
96 ms |
94356 KB |
Output is correct |
8 |
Correct |
277 ms |
103840 KB |
Output is correct |
9 |
Execution timed out |
3054 ms |
100600 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |