답안 #1019586

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1019586 2024-07-11T04:24:24 Z boyliguanhan Fish (IOI08_fish) C++17
100 / 100
860 ms 36544 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;
      |                     ~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16700 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16728 KB Output is correct
2 Correct 8 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16732 KB Output is correct
2 Correct 124 ms 23488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 9 ms 16732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 54 ms 20296 KB Output is correct
2 Correct 74 ms 20512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 16984 KB Output is correct
2 Correct 10 ms 16824 KB Output is correct
3 Correct 11 ms 16988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 88 ms 23024 KB Output is correct
2 Correct 197 ms 23700 KB Output is correct
3 Correct 213 ms 24484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 129 ms 24260 KB Output is correct
2 Correct 149 ms 24216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 74 ms 23232 KB Output is correct
2 Correct 182 ms 23664 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 24008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 24516 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 162 ms 23620 KB Output is correct
2 Correct 260 ms 25912 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 441 ms 26292 KB Output is correct
2 Correct 335 ms 26036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 325 ms 27328 KB Output is correct
2 Correct 331 ms 25792 KB Output is correct
3 Correct 442 ms 30244 KB Output is correct
4 Correct 343 ms 25796 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 504 ms 27504 KB Output is correct
2 Correct 860 ms 36544 KB Output is correct
3 Correct 768 ms 36544 KB Output is correct
4 Correct 822 ms 33644 KB Output is correct