# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
307059 |
2020-09-26T22:08:39 Z |
ant101 |
Wall (IOI14_wall) |
C++14 |
|
1673 ms |
219688 KB |
#include "wall.h"
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
#include <complex>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db;
typedef string str;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
#define mp make_pair
#define f first
#define s second
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) (x).rbegin(), (x).rend()
#define rsz resize
#define ins insert
#define ft front()
#define bk back()
#define pf push_front
#define pb push_back
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e6+5;
const ll INF = 1e18;
const ld PI = 4*atan((ld)1);
const int dx[4] = {0,1,0,-1}, dy[4] = {1,0,-1,0};
namespace io {
void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }
void setIO(string s = "") {
ios_base::sync_with_stdio(0); cin.tie(0); // fast I/O
// cin.exceptions(cin.failbit); // ex. throws exception when you try to read letter into int
if (sz(s)) {
setIn(s+".in");
setOut(s+".out");
} // for USACO
}
}
using namespace io;
namespace input {
template<class T> void re(complex<T>& x);
template<class T1, class T2> void re(pair<T1,T2>& p);
template<class T> void re(vector<T>& a);
template<class T, size_t SZ> void re(array<T,SZ>& a);
template<class T> void re(T& x) { cin >> x; }
void re(double& x) { string t; re(t); x = stod(t); }
void re(ld& x) { string t; re(t); x = stold(t); }
template<class Arg, class... Args> void re(Arg& first, Args&... rest) {
re(first); re(rest...);
}
template<class T> void re(complex<T>& x) { T a,b; re(a,b); x = cd(a,b); }
template<class T1, class T2> void re(pair<T1,T2>& p) { re(p.f,p.s); }
template<class T> void re(vector<T>& a) { F0R(i,sz(a)) re(a[i]); }
template<class T, size_t SZ> void re(array<T,SZ>& a) { F0R(i,SZ) re(a[i]); }
}
namespace output {
template<class T1, class T2> void pr(const pair<T1,T2>& x);
template<class T, size_t SZ> void pr(const array<T,SZ>& x);
template<class T> void pr(const vector<T>& x);
template<class T> void pr(const set<T>& x);
template<class T1, class T2> void pr(const map<T1,T2>& x);
template<class T> void pr(const T& x) { cout << x; }
template<class Arg, class... Args> void pr(const Arg& first, const Args&... rest) {
pr(first); pr(rest...);
}
template<class T1, class T2> void pr(const pair<T1,T2>& x) {
pr("{",x.f,", ",x.s,"}");
}
template<class T> void prContain(const T& x) {
pr("{");
bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; // const needed for vector<bool>
pr("}");
}
template<class T, size_t SZ> void pr(const array<T,SZ>& x) { prContain(x); }
template<class T> void pr(const vector<T>& x) { prContain(x); }
template<class T> void pr(const set<T>& x) { prContain(x); }
template<class T1, class T2> void pr(const map<T1,T2>& x) { prContain(x); }
void ps() { pr("\n"); }
template<class Arg> void ps(const Arg& first) {
pr(first); ps(); // no space at end of line
}
template<class Arg, class... Args> void ps(const Arg& first, const Args&... rest) {
pr(first," "); ps(rest...); // print w/ spaces
}
}
using namespace output;
using namespace input;
ll add(ll a, ll b) {
a += b;
if(a >= MOD) {
a -= MOD;
}
return a;
}
ll sub(ll a, ll b) {
a -= b;
if(a < 0) {
a += MOD;
}
return a;
}
ll mul(ll a, ll b) {
return (a * b)%MOD;
}
void add_self(ll& a, ll b) {
a = add(a, b);
}
void sub_self(ll& a, ll b) {
a = sub(a, b);
}
void mul_self(ll& a, ll b) {
a = mul(a, b);
}
pl lazy[4*MX];
pl t[4*MX];
ll N, K;
// blue = add
// green = delete
void push(ll curr) {
if (lazy[curr].f != -2) {
// ps(lazy[curr].f);
t[curr*2] = {min(max(t[curr*2].f, lazy[curr].f), lazy[curr].s), max(min(t[curr*2].s, lazy[curr].s), lazy[curr].first)};
t[curr*2+1] = {min(max(t[curr*2+1].f, lazy[curr].f), lazy[curr].s), max(min(t[curr*2+1].s, lazy[curr].s), lazy[curr].first)};
lazy[curr*2] = {min(max(lazy[curr*2].f, lazy[curr].f), lazy[curr].s), max(min(lazy[curr*2].s, lazy[curr].s), lazy[curr].first)};
lazy[curr*2+1] = {min(max(lazy[curr*2+1].f, lazy[curr].f), lazy[curr].s), max(min(lazy[curr*2+1].s, lazy[curr].s), lazy[curr].first)};
lazy[curr] = {-2, 1e14};
}
}
void upd(ll curr, ll tl, ll tr, ll l, ll r, ll f, ll s) {
if (l > r) {
return;
}
if (tl == l && tr == r) {
t[curr] = {min(max(t[curr].f, f), s), max(min(t[curr].s, s), f)};
lazy[curr] = {min(max(lazy[curr].f, f), s), max(min(lazy[curr].s, s), f)};
return;
}
push(curr);
ll tm = (tl+tr)/2;
upd(curr*2, tl, tm, l, min(tm, r), f, s);
upd(curr*2+1, tm+1, tr, max(l, tm+1), r, f, s);
t[curr] = {min(t[curr*2].f, t[curr*2+1].f), max(t[curr*2].s, t[curr*2+1].s)};
}
pl qry(ll curr, ll tl, ll tr, ll l, ll r) {
if (l > r) {
return {1e13, -1};
}
if (tl == l && tr == r) {
return t[curr];
}
push(curr);
ll tm = (tl+tr)/2;
pl q1 = qry(curr*2, tl, tm, l, min(tm, r));
pl q2 = qry(curr*2+1, tm+1, tr, max(l, tm+1), r);
return {min(q1.f, q2.f), max(q1.s, q2.s)};
}
void buildWall(int n, int k, int op[], int left[], int right[], int height[], int finalHeight[]) {
N = n;
K = k;
F0R (i, MX*4) {
lazy[i] = {-1, 1e13};
}
F0R (i, K) {
if (op[i] == 1) {
upd(1, 1, N, left[i]+1, right[i]+1, height[i], 1e13);
} else {
upd(1, 1, N, left[i]+1, right[i]+1, -1, height[i]);
}
}
F0R (i, N) {
finalHeight[i] = qry(1, 1, N, i+1, i+1).f;
}
return;
}
Compilation message
wall.cpp: In function 'void io::setIn(std::string)':
wall.cpp:68:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
68 | void setIn(string s) { freopen(s.c_str(),"r",stdin); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
wall.cpp: In function 'void io::setOut(std::string)':
wall.cpp:69:36: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
69 | void setOut(string s) { freopen(s.c_str(),"w",stdout); }
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
72 ms |
125560 KB |
Output is correct |
2 |
Correct |
77 ms |
125816 KB |
Output is correct |
3 |
Correct |
74 ms |
125688 KB |
Output is correct |
4 |
Correct |
84 ms |
126340 KB |
Output is correct |
5 |
Correct |
82 ms |
126328 KB |
Output is correct |
6 |
Correct |
82 ms |
126328 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
74 ms |
125560 KB |
Output is correct |
2 |
Correct |
255 ms |
136056 KB |
Output is correct |
3 |
Correct |
345 ms |
131576 KB |
Output is correct |
4 |
Correct |
1004 ms |
140388 KB |
Output is correct |
5 |
Correct |
498 ms |
140936 KB |
Output is correct |
6 |
Correct |
491 ms |
140920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
125548 KB |
Output is correct |
2 |
Correct |
76 ms |
125688 KB |
Output is correct |
3 |
Correct |
76 ms |
125688 KB |
Output is correct |
4 |
Correct |
85 ms |
126332 KB |
Output is correct |
5 |
Correct |
81 ms |
126328 KB |
Output is correct |
6 |
Correct |
81 ms |
126332 KB |
Output is correct |
7 |
Correct |
72 ms |
125560 KB |
Output is correct |
8 |
Correct |
247 ms |
135672 KB |
Output is correct |
9 |
Correct |
352 ms |
132344 KB |
Output is correct |
10 |
Correct |
1004 ms |
140408 KB |
Output is correct |
11 |
Correct |
497 ms |
140924 KB |
Output is correct |
12 |
Correct |
490 ms |
140920 KB |
Output is correct |
13 |
Correct |
73 ms |
125560 KB |
Output is correct |
14 |
Correct |
251 ms |
135672 KB |
Output is correct |
15 |
Correct |
121 ms |
127736 KB |
Output is correct |
16 |
Correct |
1026 ms |
140708 KB |
Output is correct |
17 |
Correct |
498 ms |
140792 KB |
Output is correct |
18 |
Correct |
505 ms |
140668 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
73 ms |
125560 KB |
Output is correct |
2 |
Correct |
74 ms |
125688 KB |
Output is correct |
3 |
Correct |
75 ms |
125692 KB |
Output is correct |
4 |
Correct |
83 ms |
126328 KB |
Output is correct |
5 |
Correct |
81 ms |
126328 KB |
Output is correct |
6 |
Correct |
82 ms |
126328 KB |
Output is correct |
7 |
Correct |
73 ms |
125556 KB |
Output is correct |
8 |
Correct |
250 ms |
135764 KB |
Output is correct |
9 |
Correct |
343 ms |
132344 KB |
Output is correct |
10 |
Correct |
989 ms |
140536 KB |
Output is correct |
11 |
Correct |
498 ms |
140920 KB |
Output is correct |
12 |
Correct |
496 ms |
140920 KB |
Output is correct |
13 |
Correct |
73 ms |
125560 KB |
Output is correct |
14 |
Correct |
251 ms |
135812 KB |
Output is correct |
15 |
Correct |
120 ms |
127736 KB |
Output is correct |
16 |
Correct |
1057 ms |
140644 KB |
Output is correct |
17 |
Correct |
514 ms |
140792 KB |
Output is correct |
18 |
Correct |
506 ms |
140828 KB |
Output is correct |
19 |
Correct |
1673 ms |
219688 KB |
Output is correct |
20 |
Correct |
1623 ms |
217256 KB |
Output is correct |
21 |
Correct |
1629 ms |
219640 KB |
Output is correct |
22 |
Correct |
1622 ms |
217176 KB |
Output is correct |
23 |
Correct |
1619 ms |
217148 KB |
Output is correct |
24 |
Correct |
1623 ms |
217208 KB |
Output is correct |
25 |
Correct |
1621 ms |
217336 KB |
Output is correct |
26 |
Correct |
1622 ms |
219640 KB |
Output is correct |
27 |
Correct |
1634 ms |
219656 KB |
Output is correct |
28 |
Correct |
1629 ms |
217208 KB |
Output is correct |
29 |
Correct |
1627 ms |
217024 KB |
Output is correct |
30 |
Correct |
1635 ms |
217336 KB |
Output is correct |