AtCoder Grand Contest 015

Submission #8396280

Source codeソースコード

#include <bits/stdc++.h>
#define rg register
#define LL long long 

using namespace std;

const int N=200010;
const int P=1e9+7;
inline int read(){
	int x=0,f=1;char ch=getchar();
	while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
	while(isdigit(ch)){x=x*10+ch-'0';ch=getchar();}
	return x*f;
}
struct node{
    int x,y;
    bool operator < (const node &bb) const {return y!=bb.y?y<bb.y:x<bb.x;}
}b[N],a[N];
int n,mx[N][20],mi[N][20],l2[N],sm=1;
int getmax(int l,int r){
    int z=l2[r-l+1];
    return max(mx[l][z],mx[r-(1<<z)+1][z]);
}
int getmin(int l,int r){
    int z=l2[r-l+1];
    return min(mi[l][z],mi[r-(1<<z)+1][z]);
}
int c[N];
void update(int x,int y){
	while(x<=n)
		c[x]=(c[x]+y)%P,x+=x&(-x);
}
int query(int x){
	int an=x>=0;
	while(x>0)
		an=(an+c[x])%P,x-=x&(-x);
	return an;
}
int main()
{
    n=read();
    for(rg int i=1;i<=n;++i) b[i].x=read(),b[i].y=read();
    sort(b+1,b+n+1);
    for(rg int i=1;i<=n;++i) mx[i][0]=mi[i][0]=b[i].x;
    for(rg int i=2;i<=n;++i) l2[i]=l2[i>>1]+1;
    for(rg int j=1;j<=l2[n];++j)
        for(rg int i=1;i+(1<<j)-1<=n;++i){
            mx[i][j]=max(mx[i][j-1],mx[i+(1<<(j-1))][j-1]);
            mi[i][j]=min(mi[i][j-1],mi[i+(1<<(j-1))][j-1]);
        }
    for(rg int i=1;i<=n;++i){
        a[i].x=a[i].y=i;
        int l=1,r=i-1;
        while(l<=r){
            int mid=(l+r)>>1;
            if(getmax(1,mid)>b[i].x) a[i].x=mid,r=mid-1;
            else l=mid+1;
        }
        l=i+1,r=n;
        while(l<=r){
            int mid=(l+r)>>1;
            if(getmin(mid,r)<b[i].x) a[i].y=mid,l=mid+1;
            else r=mid-1;
        }
    }
    sort(a+1,a+n+1);
    for(rg int i=1;i<=n;++i){
        int ll=a[i].x,rr=a[i].y;
        int nf=(sm-query(ll-2)+P)%P;
        sm=(sm+nf)%P;
        update(rr,nf);
    }
    printf("%d\n",(sm-query(n-1)+P)%P);
    return 0;
}

Submission

Task問題 E - Mr.Aoki Incubator
User nameユーザ名 luogu_bot2
Created time投稿日時
Language言語 C++14 (GCC 5.4.1)
Status状態 AC
Score得点 1200
Source lengthソースコード長 1829 Byte
File nameファイル名
Exec time実行時間 168 ms
Memory usageメモリ使用量 36224 KB

Test case

Set

Set name Score得点 / Max score Cases
Sample - s1.txt,s2.txt
All 1200 / 1200 01.txt,02.txt,03.txt,04.txt,05.txt,06.txt,07.txt,08.txt,09.txt,10.txt,11.txt,12.txt,13.txt,14.txt,15.txt,16.txt,17.txt,18.txt,19.txt,20.txt,21.txt,22.txt,23.txt,24.txt,25.txt,26.txt,27.txt,28.txt,29.txt,30.txt,31.txt,32.txt,33.txt,34.txt,s1.txt,s2.txt

Test case

Case name Status状態 Exec time実行時間 Memory usageメモリ使用量
01.txt AC 148 ms 35456 KB
02.txt AC 145 ms 35456 KB
03.txt AC 144 ms 35456 KB
04.txt AC 147 ms 35456 KB
05.txt AC 141 ms 35456 KB
06.txt AC 145 ms 35456 KB
07.txt AC 144 ms 35456 KB
08.txt AC 141 ms 35456 KB
09.txt AC 157 ms 36224 KB
10.txt AC 126 ms 35456 KB
11.txt AC 144 ms 36224 KB
12.txt AC 154 ms 36224 KB
13.txt AC 146 ms 36224 KB
14.txt AC 146 ms 36224 KB
15.txt AC 153 ms 36224 KB
16.txt AC 141 ms 36224 KB
17.txt AC 144 ms 36224 KB
18.txt AC 153 ms 36224 KB
19.txt AC 141 ms 36224 KB
20.txt AC 146 ms 36224 KB
21.txt AC 163 ms 36224 KB
22.txt AC 159 ms 36224 KB
23.txt AC 154 ms 36224 KB
24.txt AC 163 ms 36224 KB
25.txt AC 156 ms 35584 KB
26.txt AC 146 ms 35584 KB
27.txt AC 168 ms 35584 KB
28.txt AC 147 ms 35456 KB
29.txt AC 152 ms 35840 KB
30.txt AC 161 ms 35968 KB
31.txt AC 2 ms 4352 KB
32.txt AC 2 ms 4352 KB
33.txt AC 2 ms 4352 KB
34.txt AC 2 ms 4352 KB
s1.txt AC 2 ms 4352 KB
s2.txt AC 2 ms 4352 KB