# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
920524 |
2024-02-02T17:17:34 Z |
asdasdqwer |
Sails (IOI07_sails) |
C++14 |
|
180 ms |
9296 KB |
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
struct Segtree {
int n;
vector<int> mx;
vector<int> mn;
vector<int> upd;
Segtree(int sz) {
n=1;
while (n<sz)n*=2;
mx.assign(2*n,0);
mn.assign(2*n,0);
upd.assign(2*n,0);
}
void pushdown(int x) {
if (upd[x] == 0) return;
upd[2*x+1]+=upd[x];
upd[2*x+2]+=upd[x];
mx[2*x+1]+=upd[x];
mx[2*x+2]+=upd[x];
mn[2*x+1]+=upd[x];
mn[2*x+2]+=upd[x];
upd[x]=0;
}
int get(int i, int x, int lx, int rx) {
if (rx-lx==1)return mx[x];
pushdown(x);
int m=(lx+rx)/2;
if (i<m)return get(i,2*x+1,lx,m);
else return get(i,2*x+2,m,rx);
}
int get(int i) {
return get(i,0,0,n);
}
int first(int v, int x, int lx, int rx) {
if (rx-lx==1) {
return lx;
}
pushdown(x);
int m=(lx+rx)/2;
if (mx[2*x+1] >= v) return first(v, 2*x+1, lx, m);
else return first(v, 2*x+2, m, rx);
}
int last(int v, int x, int lx, int rx) {
if (rx-lx==1) {
return lx;
}
pushdown(x);
int m=(lx+rx)/2;
if (mn[2*x+2] <= v) return last(v, 2*x+2, m, rx);
else return last(v, 2*x+1, lx, m);
}
void inc(int l, int r, int x, int lx, int rx) {
if (lx >= r || rx <= l) return;
if (rx-lx==1) {
mn[x]++;
mx[x]++;
return;
}
pushdown(x);
if (lx >= l && rx <= r) {
mx[x]++;
mn[x]++;
upd[x]++;
return;
}
int m=(lx+rx)/2;
inc(l, r, 2*x+1, lx, m);
inc(l, r, 2*x+2, m, rx);
mx[x]=max(mx[2*x+1], mx[2*x+2]);
mn[x]=min(mn[2*x+1], mn[2*x+2]);
}
void inc(int l, int r) {
if (r-l <= 0) return;
inc(l, r, 0, 0, n);
}
void query(int size, int num) {
int start = n - size;
int end = start + num;
int val = get(end-1);
int f = first(val, 0, 0, n), s = last(val, 0, 0, n);
f = max(f, start);
inc(start, f);
num -= f - start;
inc(s - num + 1, s+1);
}
int res() {
int rr=0;
for (int i=0;i<n;i++) {
int tmp=get(i);
rr += (tmp*(tmp-1))/2;
}
return rr;
}
};
signed main() {
int n;cin>>n;
vector<array<int,2>> v(n);
for (auto &x:v) {
cin>>x[0]>>x[1];
}
Segtree sg(100000);
sort(v.begin(),v.end());
for (auto &x:v) {
sg.query(x[0], x[1]);
}
cout<<sg.res()<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
6488 KB |
Output is correct |
2 |
Correct |
9 ms |
6488 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
6492 KB |
Output is correct |
2 |
Correct |
10 ms |
6612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
6488 KB |
Output is correct |
2 |
Correct |
9 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
6748 KB |
Output is correct |
2 |
Correct |
10 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
12 ms |
6492 KB |
Output is correct |
2 |
Correct |
11 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
6744 KB |
Output is correct |
2 |
Correct |
53 ms |
7268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
52 ms |
7364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
86 ms |
7920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
140 ms |
8632 KB |
Output is correct |
2 |
Correct |
121 ms |
8532 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
180 ms |
9040 KB |
Output is correct |
2 |
Correct |
76 ms |
8704 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
171 ms |
9296 KB |
Output is correct |
2 |
Correct |
134 ms |
9200 KB |
Output is correct |