# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
163407 |
2019-11-13T07:27:06 Z |
davitmarg |
Wall (IOI14_wall) |
C++17 |
|
2329 ms |
27640 KB |
/*DavitMarg*/
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
#include <bitset>
#include <stack>
#include <cassert>
#include <iterator>
#include <fstream>
#define mod 1000000007ll
#define LL long long
#define LD long double
#define MP make_pair
#define PB push_back
#define all(v) v.begin(), v.end()
using namespace std;
#ifndef death
#include "wall.h"
#endif
const int N = 2000006;
pair<LL, LL> t[4 * N], d[4 * N];
void addLazy(pair<LL, LL> &a, pair<LL, LL> b)
{
if (b.first != -1)
if (a.first == -1)
a.first = b.first;
else
a.first = max(b.first, a.first);
if (b.second != -1)
if (a.second == -1)
a.second = b.second;
else
a.second = min(b.second, a.second);
}
pair<LL, LL> merge(pair<LL, LL> a, pair<LL, LL> b)
{
a.first = min(a.first, b.first);
a.second = max(a.second, b.second);
return a;
}
void push(int v, int l, int r, int f = 1)
{
if (l != r)
{
addLazy(d[v * 2], d[v]);
addLazy(d[v * 2 + 1], d[v]);
if (f)
{
int m = (l + r) / 2;
push(v * 2, l, m, 0);
push(v * 2 + 1, m + 1, r, 0);
}
}
if (d[v].first != -1)
t[v].first = max(t[v].first, d[v].first);
if (d[v].second != -1)
t[v].second = min(t[v].second, d[v].second);
d[v].first = d[v].second = -1;
}
void build(int v, int l, int r)
{
d[v] = MP(-1, -1);
t[v].second = mod * mod;
if (l == r)
return;
int m = (l + r) / 2;
build(v * 2, l, m);
build(v * 2 + 1, m + 1, r);
}
void add(int v, int l, int r, int i, int j, pair<LL, LL> val)
{
push(v, l, r);
if (i > j)
return;
if (l == i && r == j)
{
addLazy(d[v], val);
//cout << d[v].first << " : " << d[v].second << endl;
push(v, l, r);
return;
}
int m = (l + r) / 2;
add(v * 2, l, m, i, min(j, m), val);
add(v * 2 + 1, m + 1, r, max(i, m + 1), j, val);
t[v] = merge(t[v * 2], t[v * 2 + 1]);
}
pair<LL, LL> get(int v, int l, int r, int i, int j)
{
push(v, l, r);
if (i > j)
return MP(mod * mod, -mod * mod);
if (l == i && r == j)
return t[v];
int m = (l + r) / 2;
return merge(
get(v * 2, l, m, i, min(j, m)),
get(v * 2 + 1, m + 1, r, max(i, m + 1), j));
}
void buildWall(int n, int k, int op[], int L[], int R[], int H[], int fin[])
{
build(1, 0, n - 1);
for (int i = 0; i < k && op[i] == 1; i++)
add(1, 0, n - 1, L[i], R[i], MP(H[i], mod * mod));
for (int i = 0; i < n; i++)
{
int h = get(1, 0, n - 1, i, i).first;
add(1, 0, n - 1, i, i, MP(h, h));
}
for (int i = 0; i < k; i++)
{
if (op[i] == 1)
continue;
add(1, 0, n - 1, L[i], R[i], MP(0, H[i]));
}
for (int i = 0; i < n; i++)
fin[i] = get(1, 0, n - 1, i, i).second;
}
#ifdef death
int main()
{
int N, K, L[102], R[102], OP[102], H[102], A[102];
cin >> N >> K;
for (int i = 0; i < K; i++)
cin >> OP[i] >> L[i] >> R[i] >> H[i];
buildWall(N, K, OP, L, R, H, A);
for (int i = 0; i < N; i++)
cout << A[i] << endl;
return 0;
}
#endif
/*
10 3
1 3 4 91220
1 5 9 48623
2 3 5 39412
*/
Compilation message
wall.cpp: In function 'void addLazy(std::pair<long long int, long long int>&, std::pair<long long int, long long int>)':
wall.cpp:35:8: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
if (b.first != -1)
^
wall.cpp:41:8: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
if (b.second != -1)
^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
182 ms |
14200 KB |
Output is correct |
3 |
Correct |
685 ms |
9648 KB |
Output is correct |
4 |
Correct |
2329 ms |
26616 KB |
Output is correct |
5 |
Correct |
1054 ms |
27640 KB |
Output is correct |
6 |
Correct |
1046 ms |
26104 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
4 ms |
504 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |