# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
666242 |
2022-11-27T20:54:36 Z |
Lobo |
Roads (CEOI20_roads) |
C++17 |
|
154 ms |
11724 KB |
#include<bits/stdc++.h>
using namespace std;
const long long inf = (long long) 1e18 + 10;
const int inf1 = (int) 1e9 + 10;
// #define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
const int maxn = 2e5+10;
int n, x[maxn], y[maxn];
int cntno, val[maxn], sz[maxn], lc[maxn], rc[maxn], prior[maxn], tr[maxn], pt[maxn];
dbl findy(int i, int xcur) {
if(x[i] == x[i+1]) return y[i];
return ((dbl) y[i+1]-y[i])/((dbl) x[i+1]-x[i])*((dbl) xcur-x[i]) + (dbl) y[i];
}
int create(int i) {
int no = ++cntno;
pt[no] = i;
tr[i] = no;
val[no] = i;
sz[no] = 1;
prior[no] = rand();
return no;
}
void calc(int no) {
if(no == 0) return;
sz[no] = sz[lc[no]]+1+sz[rc[no]];
}
int merge(int l, int r) {
if(l == 0) return r;
if(r == 0) return l;
if(prior[l] <= prior[r]) {
rc[l] = merge(rc[l],r);
calc(l);
return l;
}
else {
lc[r] = merge(l,lc[r]);
calc(r);
return r;
}
}
pair<int,int> splitval(int no, int xcur, int y0, int idno) {
if(no == 0) return mp(0,0);
if(findy(pt[no],xcur) <= y0 || pt[no] == idno) {
auto aux = splitval(rc[no],xcur,y0,idno);
rc[no] = aux.fr;
calc(no);
return mp(no,aux.sc);
}
else {
auto aux = splitval(lc[no],xcur,y0,idno);
lc[no] = aux.sc;
calc(no);
return mp(aux.fr,no);
}
}
pair<int,int> splitsz(int no, int szlf) {
if(no == 0) return mp(0,0);
if(sz[lc[no]]+1 <= szlf) {
auto aux = splitsz(rc[no],szlf-sz[lc[no]]-1);
rc[no] = aux.fr;
calc(no);
return mp(no,aux.sc);
}
else {
auto aux = splitsz(lc[no],szlf);
lc[no] = aux.sc;
calc(no);
return mp(aux.fr,no);
}
}
int rightmost(int no) {
if(rc[no] == 0) return no;
return rightmost(rc[no]);
}
void solve() {
cin >> n;
vector<pair<pair<int,int>,pair<int,int>>> pts;
bool ok = 0;
for(int i = 1; i <= 2*n; i+=2) {
cin >> x[i] >> y[i];
cin >> x[i+1] >> y[i+1];
if(mp(x[i],y[i]) == mp(x[i+1],y[i+1])) ok = 1;
if(mp(x[i],y[i]) > mp(x[i+1],y[i+1])) {
swap(x[i],x[i+1]);
swap(y[i],y[i+1]);
}
pts.pb(mp(mp(x[i],y[i]),mp(i,1)));
pts.pb(mp(mp(x[i+1],y[i+1]),mp(i,-1)));
}
sort(all(pts));
x[2*n+1] = -inf1;
x[2*n+2] = inf1;
y[2*n+1] = -inf1;
y[2*n+2] = -inf1;
vector<int> vec;
vec.pb(2*n+1);
int rt = create(2*n+1);
for(auto X : pts) {
if(X.sc.sc == 1) {
int i = X.sc.fr;
int xcur = X.fr.fr;
pair<int,int> aux;
aux = splitval(rt,xcur,y[i],i);
int rt1 = aux.fr; rt = aux.sc;
int rgt = rightmost(rt1);
if(val[rgt] != 2*n+1) {
cout << x[i] << " " << y[i] << " " << x[val[rgt]] << " " << y[val[rgt]] << endl;
}
val[rgt] = i;
int rt2 = create(i);
rt = merge(rt2,rt);
rt = merge(rt1,rt);
}
else {
int i = X.sc.fr;
int xcur = X.fr.fr;
pair<int,int> aux;
aux = splitval(rt,xcur,y[i+1],i);
int rt1 = aux.fr; rt = aux.sc;
aux = splitsz(rt1,sz[rt1]-1);
int rt2 = aux.sc; rt1 = aux.fr;
int rgt = rightmost(rt1);
val[rgt] = i+1;
rt = merge(rt1,rt);
}
}
}
int32_t main() {
ios::sync_with_stdio(false); cin.tie(0);
// freopen("in.in", "r", stdin);
// freopen("out.out", "w", stdout);
int tt = 1;
// cin >> tt;
while(tt--) {
solve();
}
}
Compilation message
roads.cpp: In function 'void solve()':
roads.cpp:142:17: warning: unused variable 'rt2' [-Wunused-variable]
142 | int rt2 = aux.sc; rt1 = aux.fr;
| ^~~
roads.cpp:94:10: warning: variable 'ok' set but not used [-Wunused-but-set-variable]
94 | bool ok = 0;
| ^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
57 ms |
4436 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
2 ms |
468 KB |
Output is correct |
4 |
Correct |
9 ms |
1620 KB |
Output is correct |
5 |
Correct |
21 ms |
2768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
10 ms |
1620 KB |
Output is correct |
5 |
Correct |
18 ms |
2768 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
10 ms |
1676 KB |
Output is correct |
10 |
Correct |
152 ms |
11724 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
10 ms |
1728 KB |
Output is correct |
5 |
Correct |
19 ms |
2800 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
368 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
9 ms |
1620 KB |
Output is correct |
10 |
Correct |
47 ms |
6120 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
468 KB |
Output is correct |
5 |
Correct |
9 ms |
1620 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
2 ms |
468 KB |
Output is correct |
9 |
Correct |
11 ms |
1728 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
468 KB |
Output is correct |
13 |
Correct |
10 ms |
1716 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
2 ms |
468 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
5 ms |
928 KB |
Output is correct |
23 |
Correct |
5 ms |
852 KB |
Output is correct |
24 |
Correct |
11 ms |
1264 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
52 ms |
4420 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
10 ms |
1620 KB |
Output is correct |
7 |
Correct |
19 ms |
2900 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
2 ms |
468 KB |
Output is correct |
11 |
Correct |
10 ms |
1620 KB |
Output is correct |
12 |
Correct |
154 ms |
11592 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
328 KB |
Output is correct |
15 |
Correct |
2 ms |
460 KB |
Output is correct |
16 |
Correct |
9 ms |
1620 KB |
Output is correct |
17 |
Correct |
47 ms |
6256 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
336 KB |
Output is correct |
24 |
Correct |
2 ms |
468 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
5 ms |
852 KB |
Output is correct |
27 |
Correct |
5 ms |
852 KB |
Output is correct |
28 |
Correct |
10 ms |
1356 KB |
Output is correct |
29 |
Correct |
82 ms |
6364 KB |
Output is correct |
30 |
Correct |
108 ms |
8808 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
106 ms |
7696 KB |
Output is correct |
33 |
Correct |
103 ms |
7692 KB |
Output is correct |
34 |
Correct |
141 ms |
10172 KB |
Output is correct |
35 |
Correct |
143 ms |
10436 KB |
Output is correct |
36 |
Correct |
143 ms |
10100 KB |
Output is correct |