Submission #1019585

# Submission time Handle Problem Language Result Execution time Memory
1019585 2024-07-11T04:22:41 Z vjudge1 Fish (IOI08_fish) C++17
100 / 100
835 ms 44760 KB
#include<bits/stdc++.h>
using namespace std;
int mod=0,ans;
vector<int>S[1<<19];
inline int cntof(int i,int j){
    return lower_bound(S[j].begin(),S[j].end(),S[i].back()+2>>1)-S[j].begin();
}
struct segtree{
    int T[1<<20];
    segtree(){for(auto&i:T)i=1;}
    void upd(int i,int l,int r,int p,int x){
        if(l==r)return void(T[i]=(T[i]+x)%mod);
        if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
        else upd(i*2+1,l+r+2>>1,r,p,x);
        T[i]=T[i*2]*T[i*2+1]%mod;
    }
    int qry(int i,int l,int r,int ll,int rr){
        if(l>rr||ll>r)return 1;
        if(ll<=l&&r<=rr)return T[i];
        return qry(i*2,l,l+r>>1,ll,rr)*
            qry(i*2+1,l+r+2>>1,r,ll,rr)%mod;
    }
} ST;
void dothestuf(int l,int r,int x,int k){
    ans=(ans+mod+x*ST.qry(1,1,k,l,r))%mod;
}
vector<int>order;
int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n,k;
    cin>>n>>k>>mod;
    vector<pair<int,int>>anchovies;
    for(int i=1;i<=n;i++){
        int a,b;cin>>a>>b;
        S[b].push_back(a);
    }
    for(int i=1;i<=k;i++)
        sort(S[i].begin(),S[i].end());
    sort(S+1,S+k+1,[](vector<int>a,vector<int>b){
        return a.back()<b.back();
    });
    for(int i=1;i<=k;i++) for(auto j:S[i])
        anchovies.push_back({j,i});
    sort(anchovies.begin(),anchovies.end());
    int ID=0;
    for(int i=1;i<=k;i++){
        while(ID<n&&anchovies[ID].first<=S[i].back()/2)
            ST.upd(1,1,k,anchovies[ID++].second,1);
        ST.upd(1,1,k,i,-1);
        dothestuf(1,i,1,k);
        int kv=S[i][cntof(i,i)];
        int v2=k+1,l=1,r=k;
        while(l<=r){
            int mid=l+r>>1;
            if(S[mid].back()>=2*kv)
                r=mid-1,v2=mid;
            else l=mid+1;
        }
        dothestuf(1,v2-1,-1,k);
        ST.upd(1,1,k,i,1);
        dothestuf(1,v2-1,1,k);
    }
    cout<<ans;
}

Compilation message

fish.cpp: In function 'int cntof(int, int)':
fish.cpp:6:59: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
    6 |     return lower_bound(S[j].begin(),S[j].end(),S[i].back()+2>>1)-S[j].begin();
      |                                                ~~~~~~~~~~~^~
fish.cpp: In member function 'void segtree::upd(int, int, int, int, int)':
fish.cpp:13:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |         if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
      |            ~^~
fish.cpp:13:33: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   13 |         if(l+r>>1>=p)upd(i*2,l,l+r>>1,p,x);
      |                                ~^~
fish.cpp:14:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   14 |         else upd(i*2+1,l+r+2>>1,r,p,x);
      |                        ~~~^~
fish.cpp: In member function 'int segtree::qry(int, int, int, int, int)':
fish.cpp:20:27: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   20 |         return qry(i*2,l,l+r>>1,ll,rr)*
      |                          ~^~
fish.cpp:21:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   21 |             qry(i*2+1,l+r+2>>1,r,ll,rr)%mod;
      |                       ~~~^~
fish.cpp: In function 'int main()':
fish.cpp:54:22: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   54 |             int mid=l+r>>1;
      |                     ~^~
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 8 ms 16732 KB Output is correct
2 Correct 9 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 16732 KB Output is correct
2 Correct 127 ms 29448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 56 ms 22600 KB Output is correct
2 Correct 73 ms 23424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 16988 KB Output is correct
2 Correct 10 ms 16988 KB Output is correct
3 Correct 11 ms 17004 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 89 ms 26936 KB Output is correct
2 Correct 189 ms 30400 KB Output is correct
3 Correct 238 ms 31140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 128 ms 30360 KB Output is correct
2 Correct 151 ms 31176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 27588 KB Output is correct
2 Correct 155 ms 30792 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 30152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 31732 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 163 ms 29892 KB Output is correct
2 Correct 302 ms 33668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 406 ms 33288 KB Output is correct
2 Correct 377 ms 30548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 327 ms 32452 KB Output is correct
2 Correct 320 ms 33616 KB Output is correct
3 Correct 421 ms 37084 KB Output is correct
4 Correct 324 ms 33548 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 491 ms 35524 KB Output is correct
2 Correct 835 ms 43864 KB Output is correct
3 Correct 772 ms 44760 KB Output is correct
4 Correct 727 ms 41668 KB Output is correct