# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
879700 |
2023-11-27T23:37:44 Z |
OAleksa |
Sails (IOI07_sails) |
C++14 |
|
83 ms |
13024 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f first
#define s second
const int maxn = 1e6 + 69;
int n, a[maxn], b[maxn], st[4 * maxn], lzy[4 * maxn];
void push(int v) {
if (lzy[v] > 0) {
lzy[v * 2] += lzy[v];
lzy[v * 2 + 1] += lzy[v];
st[v * 2] += lzy[v];
st[v * 2 + 1] += lzy[v];
lzy[v] = 0;
}
}
void upd(int v, int tl, int tr, int l, int r, int val) {
if (tl > r || tr < l)
return;
else if (tl >= l && tr <= r) {
lzy[v] += val;
st[v] += val;
}
else {
push(v);
int mid = (tl + tr) / 2;
upd(v * 2, tl, mid, l, r, val);
upd(v * 2 + 1, mid + 1, tr, l, r, val);
st[v] = max(st[v * 2], st[v * 2 + 1]);
}
}
int qry(int v, int tl, int tr, int pos) {
if (tl == tr)
return st[v];
else {
int mid = (tl + tr) / 2;
push(v);
if (pos <= mid)
return qry(v * 2, tl, mid, pos);
else
return qry(v * 2 + 1, mid + 1, tr, pos);
}
}
int gas(int v, int tl, int tr, int x) {
if (tl == tr)
return tl;
else {
push(v);
int mid = (tl + tr) / 2;
if (st[v * 2] > x)
return gas(v * 2, tl, mid, x);
else
return gas(v * 2 + 1, mid + 1, tr, x);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n;
for (int i = 1;i <= n;i++)
cin >> a[i] >> b[i];
sort(a + 1, a + n + 1);
const int m = 1e6;
for (int i = 1;i <= n;i++) {
//range od [1, a[i]]
//popunjavam [a[i] - b[i] + 1, a[i]]
int l = a[i] - b[i] + 1, r = a[i];
int x = qry(1, 1, m, l), y = -1;
if (b[i] != a[i])
y = qry(1, 1, m, l - 1);
if (x == y) {
//ovde neko sranje tolko ne radi lol
int z = gas(1, 1, m, x - 1);
int kurac = gas(1, 1, m, x) + 1;
int d = z - l + 1;
upd(1, 1, m, kurac, kurac + d - 1, 1);
upd(1, 1, m, z + 1, r, 1);
}
else
upd(1, 1, m, l, r, 1);
}
cout << st[1];
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
12636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6492 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
12636 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
6488 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
6748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
7 ms |
9308 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
26 ms |
9304 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
41 ms |
11976 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
63 ms |
12888 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
83 ms |
13012 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
82 ms |
13024 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |