이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef int64_t llo;
#define mp make_pair
#define pb push_back
#define a first
#define b second
//#define endl '\n'
int n,m;
string aa[100001];
vector<string> tree[400001];
void build(int no,int l,int r){
if(l==r){
tree[no].pb("");
for(int i=(int)(aa[l].size())-1;i>=0;i--){
tree[no][0]+=aa[l][i];
}
//tree[no].pb(aa[l]);
}
else{
int mid=(l+r)/2;
build(no*2+1,l,mid);
build(no*2+2,mid+1,r);
int ind=0;
int ind2=0;
while(ind<tree[no*2+1].size() and ind2<tree[no*2+2].size()){
if(tree[no*2+1][ind]<tree[no*2+2][ind2]){
tree[no].pb(tree[no*2+1][ind]);
ind+=1;
}
else{
tree[no].pb(tree[no*2+2][ind2]);
ind2+=1;
}
}
while(ind<tree[no*2+1].size()){
tree[no].pb(tree[no*2+1][ind]);
ind+=1;
}
while(ind2<tree[no*2+2].size()){
tree[no].pb(tree[no*2+2][ind2]);
ind2+=1;
}
}
}
string cur;
string cur2;
int query(int no,int l,int r,int aa,int bb){
if(r<aa or l>bb or aa>bb){
return 0;
}
if(aa<=l and r<=bb){
int x=lower_bound(tree[no].begin(),tree[no].end(),cur2)-tree[no].begin()-1;
x-=lower_bound(tree[no].begin(),tree[no].end(),cur)-tree[no].begin();
return x+1;
}
else{
int mid=(l+r)/2;
return query(no*2+1,l,mid,aa,bb)+query(no*2+2,mid+1,r,aa,bb);
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>n>>m;
for(int i=0;i<n;i++){
cin>>aa[i];
}
sort(aa,aa+n);
build(0,0,n-1);
while(m--){
string s,tt;
cin>>s>>tt;
int x=lower_bound(aa,aa+n,s)-aa;
string ss;
ss=s;
ss[ss.size()-1]++;
int y=lower_bound(aa,aa+n,ss)-aa-1;
string t="";
for(int i=(int)(tt.size())-1;i>=0;i--){
t+=tt[i];
}
cur=t;
cur2=t;
cur2[cur2.size()-1]++;
// cout<<x<<','<<y<<endl;
cout<<query(0,0,n-1,x,y)<<'\n';
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
selling_rna.cpp: In function 'void build(int, int, int)':
selling_rna.cpp:26:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ind<tree[no*2+1].size() and ind2<tree[no*2+2].size()){
~~~^~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:26:41: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ind<tree[no*2+1].size() and ind2<tree[no*2+2].size()){
~~~~^~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:36:12: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ind<tree[no*2+1].size()){
~~~^~~~~~~~~~~~~~~~~~~~
selling_rna.cpp:40:13: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
while(ind2<tree[no*2+2].size()){
~~~~^~~~~~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |