Submission #400513

# Submission time Handle Problem Language Result Execution time Memory
400513 2021-05-08T08:37:53 Z A_D Boat (APIO16_boat) C++14
0 / 100
2000 ms 332 KB
#include <bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define F first
#define S second
#define du long double
using namespace std;
const int N=1e3+1;
const int M=1e6+100;
const int MOD=1e9+7;
int a[N];
int b[N];
int seg[4*M];
void update(int p,int s,int e,int i,int v)
{
    if(s==e){
        seg[p]+=v;
        seg[p]%=MOD;
        return;
    }
    int mid=(s+e)/2;
    if(i<=mid){
        update(p*2,s,mid,i,v);
    }
    else{
        update(p*2+1,mid+1,e,i,v);
    }
    seg[p]=(seg[p*2]+seg[p*2+1])%MOD;
}
int get(int p,int s,int e,int a,int b)
{
    if(a<=s&&e<=b){
        return seg[p];
    }
    if(s>b||e<a){
        return 0;
    }
    int mid=(s+e)/2;
    return (get(p*2,s,mid,a,b)+get(p*2+1,mid+1,e,a,b))%MOD;
}
void fix()
{
    cout<<endl<<endl;
    for(int i=1;i<=7;i++)cout<<get(1,1,M,i,i)<<" ";cout<<endl;
    cout<<endl<<endl;
}
void solve()
{
    int n,ans=0,mn=1e9;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i]>>b[i];
        mn=min(mn,a[i]);
    }
    for(int i=1;i<=n;i++){
       // fix();
        a[i]=a[i]-mn+2;
        b[i]=b[i]-mn+2;
        for(int j=a[i];j<=b[i];j++){
            int v=get(1,1,M,1,j-1)+1;
//            cout<<v<<" ";
            ans+=v;
            ans%=MOD;
        }
  //      cout<<endl;
        for(int j=b[i];j>=a[i];j--){
            int v=get(1,1,M,1,j-1)+1;
            update(1,1,M,j,v);
        }
    }
    cout<<ans<<endl;
    /*
    while(1){
        int a,b;
        cin>>a>>b;
        cout<<get(1,1,M,a,b)<<endl;
    }
    */
}
main()
{
    int t=1;
//    cin>>t;
    while(t--)solve();
}

Compilation message

boat.cpp: In function 'void fix()':
boat.cpp:44:5: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   44 |     for(int i=1;i<=7;i++)cout<<get(1,1,M,i,i)<<" ";cout<<endl;
      |     ^~~
boat.cpp:44:52: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   44 |     for(int i=1;i<=7;i++)cout<<get(1,1,M,i,i)<<" ";cout<<endl;
      |                                                    ^~~~
boat.cpp: At global scope:
boat.cpp:80:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   80 | main()
      |      ^
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 2089 ms 204 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -