Submission #51536

#TimeUsernameProblemLanguageResultExecution timeMemory
51536Retro3014허수아비 (JOI14_scarecrows)C++17
0 / 100
181 ms12852 KiB
#include <iostream>
#include <vector>
#include <algorithm>

#define MAX_N 200003
#define INF 2000000000
using namespace std;

int seg[MAX_N*4+1];

struct S{
    int x, y;
};
bool sf1(S a, S b){
    return a.x<b.x;
}
bool sf2(S a, S b){
    return a.y<b.y;
}
int N;
vector<S> v, v1;
vector<int> v2;

int idx[MAX_N+1];

void update(int x, int y)
{
    while(x>0)
    {
        seg[x]+=y;
        x/=2;
    }
}

int sum(int x, int y)
{
    int s=0;
    while(x<=y)
    {
        if(x==y)
        {
            s+=seg[x];
            return s;
        }
        if(x%2)
        {
            s+=seg[x];
            x++;
        }
        if(!(y%2))
        {
            s+=seg[y];
            y--;
        }
        x/=2;
        y/=2;
    }
    return s;
}

long long ans;

int two=1;

int main()
{
    scanf("%d", &N);
    while(two<=(N+1))   two*=2;
    for(int i=1; i<=N; i++)
    {
        S scan;
        scanf("%d%d", &scan.x, &scan.y);
        v1.push_back(scan);
    }
    sort(v1.begin(), v1.end(), sf2);
    for(int i=0; i<N; i++)
    {
        v.push_back({v1[i].x, i});
    }
    v.push_back({-1, N});
    sort(v.begin(), v.end(), sf1);
    N++;
    v1.clear();
    for(int i=N-1; i>=0; i--)
    {
        while(!v2.empty() && v[v2.back()].y<v[i].y)
        {
            idx[v2.back()]=i;
            v2.pop_back();
        }
        v2.push_back(i);
    }
    for(int i=1; i<N; i++)
    {
        int t=sum(two, two+v[i].y);
        ans+=(long long)t;
        update(two+v[i].y, 1-t);
        update(two+v[idx[i]].y, t);
    }
    cout<<ans;
    return 0;
}

Compilation message (stderr)

scarecrows.cpp: In function 'int main()':
scarecrows.cpp:67:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &N);
     ~~~~~^~~~~~~~~~
scarecrows.cpp:72:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d", &scan.x, &scan.y);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...