Submission #52639

# Submission time Handle Problem Language Result Execution time Memory
52639 2018-06-26T10:22:00 Z gs18115 허수아비 (JOI14_scarecrows) C++14
100 / 100
665 ms 149688 KB
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#define FI first
#define SE second
#define PB push_back
#define MP make_pair
using namespace std;
typedef long long LL;
typedef pair<LL,LL>PL;
typedef vector<LL>VL;
typedef set<LL>SL;
const LL INF=1LL<<55LL;
struct SCW
{
    LL x,y;
}x[234567],y[234567],P[234567];
bool cmp1(SCW X,SCW Y)
{
    return X.x<Y.x;
}
bool cmp2(SCW X,SCW Y)
{
    return X.x>Y.x;
}
bool cmp3(SCW X,SCW Y)
{
    return X.y<Y.y;
}
SCW min(SCW X,SCW Y)
{
    if(X.x>Y.x)
        return Y;
    return X;
}
LL N,N2,C,s,i;
SCW xmi;
vector<SCW>seg[876543];
void SUM(LL N,LL x1,LL x2,LL X1,LL X2)
{
    if(x1>x2||X1>X2||x1>X2||x2<X1)
        return;
    if(X1>=x1&&X2<=x2)
    {
        if(!seg[N].empty())
        {
            vector<SCW>::iterator it=upper_bound(seg[N].begin(),seg[N].end(),xmi,cmp2);
            xmi=min(xmi,seg[N].back());
            s+=seg[N].end()-it;
        }
        return;
    }
    LL mid=X1+X2>>1;
    SUM(N<<1,x1,x2,X1,mid);
    SUM((N<<1)+1,x1,x2,mid+1,X2);
    return;
}
void IN(LL N,SCW X)
{
    if(!seg[N].empty())
        seg[N].erase(upper_bound(seg[N].begin(),seg[N].end(),X,cmp3),seg[N].end());
    seg[N].PB(X);
    if(N<2)
        return;
    IN(N>>1,X);
    return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>N;
    for(N2=1;N2<N;N2<<=1);
    for(i=0;i<N;i++)
    {
        cin>>x[i].x>>y[i].x;
        x[i].y=y[i].y=i;
    }
    sort(x,x+N,cmp1);
    sort(y,y+N,cmp1);
    C=0;
    P[x[0].y].x=0;
    for(i=1;i<N;i++)
        P[x[i].y].x=++C;
    C=0;
    P[y[0].y].y=0;
    for(i=1;i<N;i++)
        P[y[i].y].y=++C;
    sort(P,P+N,cmp1);
    for(i=N;i-->0;)
    {
        xmi.x=xmi.y=INF;
        SUM(1,P[i].y+1,N2-1,0,N2-1);
        IN(N2+P[i].y,P[i]);
    }
    cout<<s<<endl;
    return 0;
}

Compilation message

scarecrows.cpp: In function 'void SUM(LL, LL, LL, LL, LL)':
scarecrows.cpp:54:14: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
     LL mid=X1+X2>>1;
            ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 19 ms 20984 KB Output is correct
2 Correct 19 ms 20984 KB Output is correct
3 Correct 21 ms 21032 KB Output is correct
4 Correct 21 ms 21188 KB Output is correct
5 Correct 21 ms 21188 KB Output is correct
6 Correct 20 ms 21340 KB Output is correct
7 Correct 20 ms 21340 KB Output is correct
8 Correct 19 ms 21352 KB Output is correct
9 Correct 19 ms 21408 KB Output is correct
10 Correct 19 ms 21416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 25 ms 22832 KB Output is correct
2 Correct 25 ms 22832 KB Output is correct
3 Correct 26 ms 22832 KB Output is correct
4 Correct 25 ms 22832 KB Output is correct
5 Correct 26 ms 22832 KB Output is correct
6 Correct 26 ms 22832 KB Output is correct
7 Correct 26 ms 22832 KB Output is correct
8 Correct 26 ms 23732 KB Output is correct
9 Correct 26 ms 23732 KB Output is correct
10 Correct 26 ms 23732 KB Output is correct
11 Correct 26 ms 23732 KB Output is correct
12 Correct 25 ms 23732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 430 ms 97988 KB Output is correct
2 Correct 569 ms 97988 KB Output is correct
3 Correct 485 ms 97988 KB Output is correct
4 Correct 242 ms 97988 KB Output is correct
5 Correct 347 ms 97988 KB Output is correct
6 Correct 457 ms 97988 KB Output is correct
7 Correct 533 ms 97988 KB Output is correct
8 Correct 665 ms 97988 KB Output is correct
9 Correct 445 ms 131468 KB Output is correct
10 Correct 526 ms 131468 KB Output is correct
11 Correct 557 ms 131468 KB Output is correct
12 Correct 622 ms 131468 KB Output is correct
13 Correct 593 ms 131468 KB Output is correct
14 Correct 461 ms 149688 KB Output is correct
15 Correct 555 ms 149688 KB Output is correct
16 Correct 620 ms 149688 KB Output is correct
17 Correct 344 ms 149688 KB Output is correct
18 Correct 445 ms 149688 KB Output is correct
19 Correct 409 ms 149688 KB Output is correct
20 Correct 398 ms 149688 KB Output is correct