Submission #987186

#TimeUsernameProblemLanguageResultExecution timeMemory
987186MrDebooFish (IOI08_fish)C++17
0 / 100
674 ms47788 KiB
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> #define mod 998244353 #define int long long #define endl '\n' using namespace std; using namespace __gnu_pbds; using ordered_set = tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update>; int N,L,R; int n,k,m; int seg[2000000]; int slv(int l=1,int r=N,int in=1){ if(r<L||l>R)return 1; if(l>=L&&r<=R)return seg[in]; int mid=(l+r)/2; return (slv(l,mid,in*2)*slv(mid+1,r,in*2+1))%m; } void dod(int in){ in+=N; seg[in]++; in/=2; while(in){ seg[in]=(seg[in*2]*seg[in*2+1])%m; in/=2; } } signed main(){ ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin>>n>>k>>m; vector<pair<int,int>>v; vector<int>vct[k]; vector<int>cnt(k); for(int i=0;i<n;i++){ int a,b; cin>>a>>b; vct[b-1].push_back(a); v.push_back({a,b-1}); } for(int i=0;i<k;i++){ int cn=0,pr=0; for(auto &w:vct[i]){ if(w>=pr*2){ cn++; pr=w; } } cnt[i]=cn; } sort(v.begin(),v.end()); N=exp2(ceil(log2(k))); for(int i=0;i<k;i++)seg[i+N]=1; for(int i=N-1;i;i--)seg[i]=(seg[i*2]*seg[i*2+1])%m; int ans=0,l=0; map<int,int>mp; for(int i=0;i<v.size();i++)mp[v[i].second]=i; for(int i=0;i<v.size();i++){ while(v[i].first>=v[l].first*2){ dod(v[l++].second); } if(mp[v[i].second]!=i)continue; int g=1; if(v[i].second>0){ L=1,R=v[i].second; g*=slv(); } if(v[i].second!=k-1){ R=k+1; L=v[i].second+2; g*=slv(); } ans+=g*cnt[v[i].second]; ans%=m; // cout<<v[i].first<<' '<<v[i].second<<' '<<ans<<endl; } cout<<ans; } /* 0110 1100 */

Compilation message (stderr)

fish.cpp: In function 'int main()':
fish.cpp:56:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int i=0;i<v.size();i++)mp[v[i].second]=i;
      |                 ~^~~~~~~~~
fish.cpp:57:18: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |     for(int i=0;i<v.size();i++){
      |                 ~^~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...