Submission #777664

#TimeUsernameProblemLanguageResultExecution timeMemory
777664salmonFish (IOI08_fish)C++14
0 / 100
2 ms2260 KiB
#include <bits/stdc++.h> using namespace std; int N,M; int mod; int l,h; vector<pair<int,int>> v; vector<pair<int,int>> oh; int mapping[500100]; bool o[500100]; int iv[500100]; struct node{ int s,e,m; long long int v; node *l,*r; node(int S, int E){ s = S; e = E; m = (s + e)/2; v = 1; if(s != e){ l = new node(s,m); r = new node(m + 1, e); } } void update(int i, int k){ if(s == e){ v += k; v %= mod; return; } if(i <= m){ l -> update(i,k); } else{ r -> update(i,k); } v = (l -> v * r -> v) % mod; } long long int query(int S, int E){ if(E < S) return 1; if(S <= s && e <= E){ return v; } long long int V = 1; if(S <= m){ V *= l -> query(S,E); } if(m < E){ V *= r -> query(S,E); } return V % mod; } }*lroot; int main(){ freopen("fsh14a.in","r",stdin); scanf(" %d",&N); scanf(" %d",&M); scanf(" %d",&mod); int next[500100]; for(int i = 1; i <= M; i++){ next[i] = -1; } for(int i = 0; i < N; i++){ scanf(" %d",&l); scanf(" %d",&h); v.push_back(make_pair(l,h)); } sort(v.begin(),v.end(),greater<pair<int,int>>()); for(int i = 0; i <= M; i++){ o[i] = true; } for(int i = 0; i < v.size(); i++){ if(o[v[i].second]){ oh.push_back(v[i]); o[v[i].second] = false; iv[v[i].second] = v.size() - 1 - i; } if(v[i].first * 2 > v[v.size() - 1 - iv[v[i].second]].first ){ next[v[i].second] = v[i].first; } } lroot = new node(0,M); int it = 0; int it1 = 0; reverse(oh.begin(),oh.end()); for(int i = 0; i < oh.size(); i++){ mapping[oh[i].second] = i; } reverse(oh.begin(),oh.end()); reverse(v.begin(),v.end()); long long int bigans = 0; M = oh.size(); for(int i = 0; i < N; i++){ while(it != N && v[i].first >= v[it].first * 2){ lroot -> update(mapping[v[it].second], 1); it++; } if(i == iv[oh.back().second]){ bigans += lroot -> query(0,M - oh.size()); //printf("v: %d %d\n",lroot -> query(0,M - oh.size()),bigans); bigans %= mod; //printf("%d %d\n",next[v[i].second],v[i].second); int e = lower_bound(oh.begin(),oh.end(),make_pair(next[v[i].second] * 2 - 1, 1100100100),greater<pair<int,int>>()) -> second; //printf("%d\n",(lroot -> query(0,mapping[v[i].second] - 1)) * (lroot -> query(mapping[v[i].second] + 1, mapping[e] ) - 1)); bigans += (lroot -> query(0,mapping[v[i].second] - 1)) * (lroot -> query(mapping[v[i].second] + 1, mapping[e] ) - 1 + mod); //bigans += lroot -> query(1,v[i].second - 1) * (long long int) lroot -> query(v[i].second + 1, M); bigans %= mod; //printf("s %d %d\n",v[i].first,bigans); oh.pop_back(); } } printf("%d",bigans); } /* * 5 3 700 8 3 7 2 4 1 2 3 2 2 5 3 7 2 2 5 1 8 3 4 1 2 3 14 500 200 1 1 1 1 1 1 1 1 2 1 2 1 2 1 2 1 3 1 3 1 3 1 3 1 3 1 3 1 3 500 200 1 1 3 2 3 1 * */

Compilation message (stderr)

fish.cpp: In function 'int main()':
fish.cpp:97:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |  for(int i = 0; i < v.size(); i++){
      |                 ~~^~~~~~~~~~
fish.cpp:115:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  115 |  for(int i = 0; i < oh.size(); i++){
      |                 ~~^~~~~~~~~~~
fish.cpp:153:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'long long int' [-Wformat=]
  153 |  printf("%d",bigans);
      |          ~^  ~~~~~~
      |           |  |
      |           |  long long int
      |           int
      |          %lld
fish.cpp:111:6: warning: unused variable 'it1' [-Wunused-variable]
  111 |  int it1 = 0;
      |      ^~~
fish.cpp:71:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   71 |     freopen("fsh14a.in","r",stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
fish.cpp:73:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |  scanf(" %d",&N);
      |  ~~~~~^~~~~~~~~~
fish.cpp:74:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |  scanf(" %d",&M);
      |  ~~~~~^~~~~~~~~~
fish.cpp:76:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |  scanf(" %d",&mod);
      |  ~~~~~^~~~~~~~~~~~
fish.cpp:85:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   85 |   scanf(" %d",&l);
      |   ~~~~~^~~~~~~~~~
fish.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |   scanf(" %d",&h);
      |   ~~~~~^~~~~~~~~~
#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...