QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#390115 | #2653. Swapping Places | kevinyang# | AC ✓ | 818ms | 83300kb | C++17 | 1.9kb | 2024-04-15 05:15:25 | 2024-04-15 05:15:26 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
struct BIT{
vector<int>arr;
int size;
void init(int n){
size = n;
arr.resize(n+5);
}
void update(int x, int val){
for(int a = x; a<=size; a+=a&-a){
arr[a]+=val;
}
}
int query(int x){
int sum = 0;
for(int a = x; a>0; a-=a&-a){
sum+=arr[a];
}
return sum;
}
void change(int x, int val){
int v = query(x)-query(x-1);
update(x,val-v);
}
int query(int x, int y){//inclusive
return query(y)-query(x-1);
}
};
signed main(){
cin.tie(nullptr)->sync_with_stdio(false);
int b,l,n;
cin >> b >> l >> n;
vector<string>arr(b+1);
for(int i = 1; i<=b; i++){
cin >> arr[i];
}
sort(arr.begin()+1,arr.end());
map<string,int>hm;
for(int i = 1; i<=b; i++){
hm[arr[i]] = i;
}
vector<vector<int>>bad(b+1,vector<int>(b+1,1LL));
for(int i = 1; i<=l; i++){
string s,t;
cin >> s >> t;
int x = hm[s];
int y = hm[t];
bad[x][y] = 0;
bad[y][x] = 0;
}
for(int i = 1; i<=b; i++){
bad[i][i] = 0;
}
vector<int>a(n+1);
for(int i = 1; i<=n; i++){
string s;
cin >> s;
a[i] = hm[s];
}
vector<BIT>bit(b+1);
for(int i = 1; i<=b; i++){
bit[i].init(n+1);
}
vector<vector<int>>idx(b+1);
for(int i = n; i>=1; i--){
idx[a[i]].push_back(i);
}
for(int i = 1; i<=b; i++){
for(int j = 1; j<=n; j++){
if(bad[i][a[j]]){
bit[i].update(j,1);
}
}
}
vector<int>ans(n+1);
for(int i = 1; i<=n; i++){
int val = 0;
for(int j = 1; j<=b; j++){
if(idx[j].size() == 0)continue;
int id = idx[j].back();
if(bit[j].query(id) == 0){
val = id;
idx[j].pop_back();
break;
}
}
//cerr << i << ' ' << val << '\n';
ans[i] = a[val];
for(int j = 1; j<=b; j++){
if(bad[j][a[val]]){
bit[j].update(val,-1);
}
}
}
for(int i = 1; i<=n; i++){
cout << arr[ans[i]];
if(i<n)cout << ' ';
}
cout << '\n';
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3596kb
input:
3 2 6 ANTILOPE CAT ANT CAT ANTILOPE ANTILOPE ANT ANT CAT CAT ANTILOPE CAT ANT
output:
ANT ANTILOPE CAT CAT CAT ANT
result:
ok single line: 'ANT ANTILOPE CAT CAT CAT ANT'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3636kb
input:
2 0 10 CAT ANT CAT ANT ANT CAT ANT ANT CAT ANT CAT ANT
output:
CAT ANT ANT CAT ANT ANT CAT ANT CAT ANT
result:
ok single line: 'CAT ANT ANT CAT ANT ANT CAT ANT CAT ANT'
Test #3:
score: 0
Accepted
time: 0ms
memory: 3704kb
input:
3 1 100 ANACONDA CAT DOG CAT DOG CAT CAT ANACONDA DOG DOG ANACONDA DOG ANACONDA DOG DOG DOG ANACONDA DOG ANACONDA DOG CAT DOG ANACONDA DOG DOG CAT DOG ANACONDA CAT CAT DOG DOG CAT ANACONDA DOG ANACONDA CAT CAT CAT CAT ANACONDA ANACONDA CAT CAT CAT ANACONDA ANACONDA CAT ANACONDA ANACONDA DOG CAT ANAC...
output:
CAT CAT ANACONDA DOG DOG ANACONDA DOG ANACONDA DOG DOG DOG ANACONDA DOG ANACONDA CAT DOG DOG ANACONDA CAT DOG DOG DOG ANACONDA CAT CAT CAT DOG DOG ANACONDA DOG ANACONDA CAT CAT CAT CAT ANACONDA ANACONDA CAT CAT CAT ANACONDA ANACONDA CAT ANACONDA ANACONDA CAT DOG ANACONDA CAT CAT DOG ANACONDA CAT ANA...
result:
ok single line: 'CAT CAT ANACONDA DOG DOG ANACO...OG DOG DOG DOG ANACONDA CAT DOG'
Test #4:
score: 0
Accepted
time: 1ms
memory: 3752kb
input:
8 24 1000 BEE CAT ZEBRA DOG ELEPHANT ANT LION TIGER BEE CAT DOG ZEBRA ELEPHANT TIGER ANT CAT ANT LION CAT ELEPHANT CAT LION DOG ELEPHANT ANT TIGER BEE LION ANT BEE CAT TIGER CAT DOG ANT DOG CAT ZEBRA LION TIGER BEE TIGER BEE DOG ELEPHANT ZEBRA ANT ZEBRA DOG TIGER ANT ELEPHANT TIGER ZEBRA LION ZEBRA ...
output:
ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ANT ...
result:
ok single line: 'ANT ANT ANT ANT ANT ANT ANT AN...A ZEBRA ZEBRA ZEBRA ZEBRA ZEBRA'
Test #5:
score: 0
Accepted
time: 9ms
memory: 5588kb
input:
2 1 100000 CAT DOG CAT DOG DOG DOG CAT DOG DOG CAT CAT DOG DOG DOG CAT DOG DOG CAT DOG DOG DOG CAT CAT CAT DOG CAT DOG DOG CAT DOG DOG CAT CAT DOG CAT CAT CAT CAT CAT DOG DOG DOG DOG DOG CAT DOG DOG DOG CAT CAT DOG CAT DOG CAT CAT CAT DOG DOG DOG CAT DOG DOG CAT CAT DOG CAT DOG DOG DOG DOG DOG DOG C...
output:
CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT CAT ...
result:
ok single line: 'CAT CAT CAT CAT CAT CAT CAT CA...DOG DOG DOG DOG DOG DOG DOG DOG'
Test #6:
score: 0
Accepted
time: 6ms
memory: 5464kb
input:
2 0 100000 DOG BEE BEE BEE DOG DOG DOG DOG DOG DOG BEE BEE DOG DOG BEE DOG DOG DOG BEE BEE BEE BEE BEE BEE BEE BEE BEE BEE DOG DOG DOG BEE DOG DOG DOG BEE DOG DOG DOG BEE DOG DOG BEE BEE BEE DOG DOG DOG DOG DOG BEE DOG DOG DOG DOG DOG DOG BEE DOG BEE BEE BEE BEE DOG BEE BEE BEE DOG DOG BEE DOG BEE B...
output:
BEE BEE DOG DOG DOG DOG DOG DOG BEE BEE DOG DOG BEE DOG DOG DOG BEE BEE BEE BEE BEE BEE BEE BEE BEE BEE DOG DOG DOG BEE DOG DOG DOG BEE DOG DOG DOG BEE DOG DOG BEE BEE BEE DOG DOG DOG DOG DOG BEE DOG DOG DOG DOG DOG DOG BEE DOG BEE BEE BEE BEE DOG BEE BEE BEE DOG DOG BEE DOG BEE BEE BEE DOG BEE DOG ...
result:
ok single line: 'BEE BEE DOG DOG DOG DOG DOG DO...DOG DOG BEE DOG DOG BEE BEE BEE'
Test #7:
score: 0
Accepted
time: 660ms
memory: 83120kb
input:
200 10000 100000 LIZARD WOBBEGONG TERMITE WHALE GROUSE SEAL REINDEER HYENA COUGAR MANATEE BINTURONG SQUIRREL GRASSHOPPER RHINOCEROS ANTELOPE VINEGAROON VULTURE MEERKAT SHREW HORSE DEGU CHOUGH MARMOSET DOG FERRET DHOLE PORPOISE PORCUPINE BUFFALO WEASEL CROW SNAKE GNU SLOTH RACCOON GAZELLE COYOTE GIRA...
output:
JAGUAR MARMOSET OWL HARE QUAIL GOLDFINCH WOLF PONY HORSE MACAQUE RACCOON COD CHAMOIS LYREBIRD ALLIGATOR JACKAL LARK WEASEL CARIBOU MANATEE PEAFOWL CRANE FOX SARDINE MINK PORCUPINE TOAD ROOK CATERPILLAR HOATZIN ORYX SQUIRREL TOAD UMBRELLABIRD PONY RACCOON GAUR ARMADILLO NIGHTINGALE FLAMINGO LIZARD MO...
result:
ok single line: 'JAGUAR MARMOSET OWL HARE QUAIL...IBEX IMPALA SNAIL TOUCAN MARMOT'
Test #8:
score: 0
Accepted
time: 545ms
memory: 83300kb
input:
200 395 100000 AL FW GF ED DV BN AC AU CL HY EK DD DR CP CY GX EU EH BM CB FQ BI GB BQ CI EE DA FE EW HL HB FA FK HU HN CE HE EZ GW HX CG CU EA EQ GC EY GT BS DC HZ AZ EI HO FT AP FZ HF CV GA HA BK CW AH FX DB GE AD FP DY AG HM CD FY AR EX GV FG CH GU DI DS CK CM EG BE CQ BD AM FI DG FO HV FU CR DQ ...
output:
AC AC ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY AD ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ AC ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZY ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ...
result:
ok single line: 'AC AC ZY ZY ZY ZY ZY ZY ZY ZY ...Z ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ ZZ'
Test #9:
score: 0
Accepted
time: 818ms
memory: 83184kb
input:
200 10000 100000 HU DT BK EY DV GG FO HO BL BE BO BM CH FC HG EG GP DE EW GI ED CF FT DI DF HV HM DA BD GF AV FD BS GH BR BU EF DX EB FS DK CI EN FR CX HN HZ EV HF FV GZ AZ HH AW GU CK HP AF GY BF BN CM DL DU BH ER GX ES GV CD BA EK AE BT AB HI AK EZ GM EA FN GC AP HL CL BP AG AD BW EM GW HK GE AC B...
output:
Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z ...
result:
ok single line: 'Z Z Z Z Z Z Z Z Z Z Z Z Z Z Z ...P HQ HR HS HT HU HV HW HX HY HZ'