Submission #51536

# Submission time Handle Problem Language Result Execution time Memory
51536 2018-06-18T08:14:14 Z Retro3014 허수아비 (JOI14_scarecrows) C++17
0 / 100
181 ms 12852 KB
#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

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 time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
2 Incorrect 2 ms 488 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 6 ms 988 KB Output is correct
2 Incorrect 7 ms 1028 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 142 ms 8896 KB Output is correct
2 Incorrect 181 ms 12852 KB Output isn't correct
3 Halted 0 ms 0 KB -