Submission #202270

#TimeUsernameProblemLanguageResultExecution timeMemory
202270SegtreeSelling RNA Strands (JOI16_selling_rna)C++14
100 / 100
964 ms56092 KiB
#include<iostream> #include<algorithm> #include<vector> #include<queue> #include<set> #include<unordered_set> #include<unordered_map> using namespace std; typedef long long ll; #define chmax(a,b) a=max(a,b) #define chmin(a,b) a=min(a,b) #define all(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<n;i++) #define mod 1000000007 #define mad(a,b) a=(a+b)%mod #define N 100010 string s[N],p[N],q[N]; ll a[N],b[N],c[N],d[N]; ll ys[N]; vector<ll> dat[2*N]; ll ret(ll c,ll d,ll k){ return lower_bound(all(dat[k]),d)-lower_bound(all(dat[k]),c); } int main(){ int n,m; cin>>n>>m; vector<pair<string,int> >v; rep(i,n){ cin>>s[i]; } rep(i,m)cin>>p[i]>>q[i]; sort(s,s+n); rep(i,m){ a[i]=lower_bound(s,s+n,p[i])-s; p[i][p[i].size()-1]++; b[i]=lower_bound(s,s+n,p[i])-s; } rep(i,n){ rep(j,s[i].size()/2)swap(s[i][j],s[i][s[i].size()-1-j]); v.push_back(make_pair(s[i],i)); } sort(v.begin(),v.end()); rep(i,n)ys[v[i].second]=i; rep(i,n)s[i]=v[i].first; rep(i,m){ rep(j,q[i].size()/2)swap(q[i][j],q[i][q[i].size()-1-j]); c[i]=lower_bound(s,s+n,q[i])-s; q[i][q[i].size()-1]++; d[i]=lower_bound(s,s+n,q[i])-s; } rep(i,n){ for(ll x=i+N;x;x>>=1){ dat[x].push_back(ys[i]); } } rep(i,2*N)sort(dat[i].begin(),dat[i].end()); rep(i,m){ ll ans=0; ll l=a[i]+N,r=b[i]+N; for(;l<r;l>>=1,r>>=1){ if(l&1)ans+=ret(c[i],d[i],l++); if(r&1)ans+=ret(c[i],d[i],--r); } cout<<ans<<endl; } }

Compilation message (stderr)

selling_rna.cpp: In function 'int main()':
selling_rna.cpp:13:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,n) for(int i=0;i<n;i++)
selling_rna.cpp:40:6:
  rep(j,s[i].size()/2)swap(s[i][j],s[i][s[i].size()-1-j]);
      ~~~~~~~~~~~~~~~           
selling_rna.cpp:40:2: note: in expansion of macro 'rep'
  rep(j,s[i].size()/2)swap(s[i][j],s[i][s[i].size()-1-j]);
  ^~~
selling_rna.cpp:13:31: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
 #define rep(i,n) for(int i=0;i<n;i++)
selling_rna.cpp:47:6:
  rep(j,q[i].size()/2)swap(q[i][j],q[i][q[i].size()-1-j]);
      ~~~~~~~~~~~~~~~           
selling_rna.cpp:47:2: note: in expansion of macro 'rep'
  rep(j,q[i].size()/2)swap(q[i][j],q[i][q[i].size()-1-j]);
  ^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...