Submission #1024164

# Submission time Handle Problem Language Result Execution time Memory
1024164 2024-07-15T14:29:48 Z lucri Sails (IOI07_sails) C++17
90 / 100
1000 ms 7428 KB
#include <bits/stdc++.h>
using namespace std;
int n;
long long ans;
pair<int,int>v[100010],tr;
struct intervale{int vmin,vmax,lazy;}aint[400010];
void qsort(int b,int e)
{
    if(b>=e)
        return;
    int bb=b,ee=e,adb=1,ade=0;
    while(bb<ee)
    {
        if(v[bb].first>v[ee].first)
        {
            tr=v[bb];
            v[bb]=v[ee];
            v[ee]=tr;
            adb=1-adb;
            ade=1-ade;
        }
        bb+=adb;
        ee-=ade;
    }
    qsort(b,bb-1);
    qsort(bb+1,e);
}
void propaga(int poz,int b,int 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;
}
int valoare(int poz,int b,int e,int 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);
}
void adauga(int poz,int b,int e,int bi,int 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;
}
int cauta1(int poz,int b,int e,int 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);
}
int cauta2(int poz,int b,int e,int 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(int i=1;i<=n;++i)
        cin>>v[i].first>>v[i].second;
    swap(v[1],v[rand()%n+1]);
    qsort(1,n);
    for(int i=1;i<=n;++i)
    {
        int poz=v[i].first-v[i].second+1;
        int val=valoare(1,1,100001,poz);
        int poz1=cauta1(1,1,100001,val);
        int 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(int 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 9 ms 3416 KB Output is correct
2 Correct 10 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3396 KB Output is correct
2 Correct 9 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 3416 KB Output is correct
2 Correct 9 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 3420 KB Output is correct
2 Correct 9 ms 3420 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 11 ms 3420 KB Output is correct
2 Correct 11 ms 3552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 3672 KB Output is correct
2 Correct 34 ms 3932 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 33 ms 3924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 58 ms 4316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 87 ms 4944 KB Output is correct
2 Correct 609 ms 7428 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 93 ms 5204 KB Output is correct
2 Correct 62 ms 4780 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 119 ms 5388 KB Output is correct
2 Execution timed out 1064 ms 3064 KB Time limit exceeded
3 Halted 0 ms 0 KB -