QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#667602 | #5541. Substring Sort | kai824 | WA | 3ms | 14808kb | C++17 | 2.8kb | 2024-10-23 00:36:13 | 2024-10-23 00:36:14 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define eb emplace_back
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
#define F first
#define S second
#define rep(i,a,b) for(int i=a;i<(b);i++)
const int mxn=1e5+5;
const int BUCK=1;
int n,q;
string parts[3][mxn/BUCK + 5];
int rankk[3][mxn/BUCK + 5];
void split(string s,int ind){
for(int i=0;i<s.length();i+=BUCK){
parts[ind][i/BUCK]=s.substr(i,BUCK);
}
}
void upd_rankk(int i){
// cerr<<i<<" 24 ok\n";
string A[3];
rep(j,0,3)A[j]=parts[j][i];
sort(A,A+3);
// cerr<<i<<" 28 ok\n";
rep(j,0,3){
rep(k,0,3){
if(parts[j][i]==A[k]){
rankk[j][i]=k;
break;
}
}
}
// cerr<<i<<"37 ok\n";
}
void move(int i1,int i2,int st,int en){
string s1=parts[i1][st/BUCK].substr(st%BUCK);
string s2=parts[i2][st/BUCK].substr(st%BUCK);
int j = st - (st%BUCK) + BUCK;
if(s1>s2){goto swapp;}
if(s1<s2)return;
for(int j=st/BUCK + 1;j<(en/BUCK);j++){
if(rankk[i1][j]>rankk[i2][j]){goto swapp;}
if(rankk[i1][j]<rankk[i2][j])return;
}
s1=parts[i1][en/BUCK].substr(0,en%BUCK + 1);
s2=parts[i2][en/BUCK].substr(0,en%BUCK + 1);
if(s1>s2){goto swapp;}
return;
swapp:;
s1=parts[i1][st/BUCK].substr(st%BUCK);//suffix of bucket
s2=parts[i2][st/BUCK].substr(st%BUCK);
// cerr<<"L50: "<<parts[i1][st/BUCK].substr(0,st%BUCK) <<" + "<<s2<<'\n';
// cerr<<"L51: "<<parts[i2][st/BUCK].substr(0,st%BUCK) <<" + "<<s1<<'\n';
parts[i1][st/BUCK] = parts[i1][st/BUCK].substr(0,st%BUCK) +s2;
parts[i2][st/BUCK] = parts[i2][st/BUCK].substr(0,st%BUCK) +s1;
// cerr<<parts[i1][st/BUCK]<<' '<<parts[i2][st/BUCK]<<'\n';
upd_rankk(st/BUCK);
for(int j=st/BUCK + 1;j<(en/BUCK);j++){
swap(parts[i1][j],parts[i2][j]);
swap(rankk [i1][j],rankk [i2][j]);
}
s1=parts[i1][en/BUCK].substr(0,en%BUCK + 1);
s2=parts[i2][en/BUCK].substr(0,en%BUCK + 1);
// cerr<<"L60: "<<s1 <<" + "<<parts[i1][en/BUCK].substr(en%BUCK+1)<<'\n';
// cerr<<"L61: "<<s2 <<" + "<<parts[i2][en/BUCK].substr(en%BUCK+1)<<'\n';
parts[i1][en/BUCK] = s2 + parts[i1][en/BUCK].substr(en%BUCK+1);
parts[i2][en/BUCK] = s1 + parts[i2][en/BUCK].substr(en%BUCK+1);
// cerr<<parts[i1][en/BUCK]<<' '<<parts[i2][en/BUCK]<<'\n';
upd_rankk(en/BUCK);
}
void output(){
for(int i=0;i<3;i++){
for(int j=0;j<=(n-1)/BUCK;j++)cout<<parts[i][j];
cout<<'\n';
}
}
int32_t main(){
ios_base::sync_with_stdio(false);cin.tie(0);
cin>>n>>q;
rep(i,0,3){
string s;
cin>>s;
split(s,i);
}
for(int i=0;i<n;i+=BUCK){
upd_rankk(i/BUCK);
}
rep(i,0,q){
int a,b;cin>>a>>b;
a--;b--;//zero-indexed: [a,b]
move(0,1,a,b);//output();
move(1,2,a,b);//output();
move(0,1,a,b);//output();
//output();
}
output();
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 14808kb
input:
5 2 icpca siaja karta 2 4 1 5
output:
iarta kiaja scpca
result:
ok 3 lines
Test #2:
score: -100
Wrong Answer
time: 3ms
memory: 14400kb
input:
6 6 aabbcc bcacab cbcaba 1 1 2 2 3 3 4 4 5 5 6 6
output:
aabbcc bcacab cbcaba
result:
wrong answer 1st lines differ - expected: 'aaaaaa', found: 'aabbcc'