# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1024173 |
2024-07-15T14:33:28 Z |
lucri |
Sails (IOI07_sails) |
C++17 |
|
113 ms |
9196 KB |
#include <bits/stdc++.h>
using namespace std;
long long n;
long long ans;
pair<long long,long long>v[100010];
struct intervale{long long vmin,vmax,lazy;}aint[400010];
static void propaga(long long poz,long long b,long long e)
{
if(b!=e)
{
aint[poz*2].lazy+=aint[poz].lazy;
aint[poz*2+1].lazy+=aint[poz].lazy;
}
aint[poz].vmax+=aint[poz].lazy;
aint[poz].vmin+=aint[poz].lazy;
aint[poz].lazy=0;
}
static long long valoare(long long poz,long long b,long long e,long long pozc)
{
propaga(poz,b,e);
if(b==e)
return aint[poz].vmin;
if((b+e)/2>=pozc)
return valoare(poz*2,b,(b+e)/2,pozc);
else
return valoare(poz*2+1,(b+e)/2+1,e,pozc);
}
static void adauga(long long poz,long long b,long long e,long long bi,long long ei)
{
if(b>ei||bi>e)
return;
propaga(poz,b,e);
if(bi<=b&&e<=ei)
{
++aint[poz].lazy;
return;
}
adauga(poz*2,b,(b+e)/2,bi,ei);
adauga(poz*2+1,(b+e)/2+1,e,bi,ei);
aint[poz].vmin=aint[poz*2+1].vmin+aint[poz*2+1].lazy;
aint[poz].vmax=aint[poz*2].vmax+aint[poz*2].lazy;
}
static long long cauta1(long long poz,long long b,long long e,long long val)
{
propaga(poz,b,e);
if(b==e)
return b;
if(aint[poz*2].vmin+aint[poz*2].lazy<=val)
return cauta1(poz*2,b,(b+e)/2,val);
return cauta1(poz*2+1,(b+e)/2+1,e,val);
}
static long long cauta2(long long poz,long long b,long long e,long long val)
{
propaga(poz,b,e);
if(b==e)
return b;
if(aint[poz*2+1].vmax+aint[poz*2+1].lazy>=val)
return cauta2(poz*2+1,(b+e)/2+1,e,val);
return cauta2(poz*2,b,(b+e)/2,val);
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
srand(time(NULL));
cin>>n;
for(long long i=1;i<=n;++i)
cin>>v[i].first>>v[i].second;
sort(v+1,v+n+1);
for(long long i=1;i<=n;++i)
{
long long poz=v[i].first-v[i].second+1;
long long val=valoare(1,1,100001,poz);
long long poz1=cauta1(1,1,100001,val);
long long poz2=min(cauta2(1,1,100001,val),v[i].first);
adauga(1,1,100001,poz1,poz1+(poz2-poz));
adauga(1,1,100001,poz2+1,v[i].first);
}
for(long long i=1;i<=100001;++i)
{
long long val=valoare(1,1,100001,i);
ans+=val*(val-1)/2;
}
cout<<ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
6488 KB |
Output is correct |
2 |
Correct |
10 ms |
6748 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
6492 KB |
Output is correct |
2 |
Correct |
9 ms |
6560 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
9 ms |
6388 KB |
Output is correct |
2 |
Correct |
11 ms |
6384 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
10 ms |
6492 KB |
Output is correct |
2 |
Correct |
11 ms |
6632 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
6492 KB |
Output is correct |
2 |
Correct |
10 ms |
6492 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
6748 KB |
Output is correct |
2 |
Correct |
35 ms |
7124 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
33 ms |
7248 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
53 ms |
7768 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
80 ms |
8528 KB |
Output is correct |
2 |
Correct |
70 ms |
8528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
83 ms |
9044 KB |
Output is correct |
2 |
Correct |
60 ms |
8640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
113 ms |
9196 KB |
Output is correct |
2 |
Correct |
84 ms |
8960 KB |
Output is correct |