QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#760270 | #9349. Exchanging Gifts | _Rosetta_ | WA | 83ms | 66168kb | C++14 | 3.6kb | 2024-11-18 15:56:04 | 2024-11-18 15:56:04 |
Judging History
answer
#include<bits/stdc++.h>
#define fo(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
#define rep(i,l,r) for(ll i(l),i##end(r);i<=i##end;++i)
#define per(i,r,l) for(ll i(r),i##end(l);i>=i##end;--i)
#define dbg(x) cerr<<#x<<" "<<x<<'\n';
#define ll long long
#define gc getchar
#define pc putchar
using namespace std;
namespace WrongIO
{
#define Ts template<typename Ty,typename... Ar>
#define Tp template<typename Ty>
Tp Ty wmax(Ty a,Ty b){return a>=b? a:b;}
Tp Ty wmin(Ty a,Ty b){return a<=b? a:b;}
Tp void read(Ty &x){x=0;Ty opt=1;char c=gc();while(!isdigit(c)&&c!='-')c=gc();if(c=='-')opt=-1,c=gc();while(isdigit(c))x=(x<<3)+(x<<1),x+=c-'0',c=gc();x*=opt;return;}
Tp void write(Ty x){short OI_USE[150],OI_top=0;if(x<=0) if(x==0)pc('0');else pc('-'),x*=-1;while(x)OI_USE[++OI_top]=x%10,x/=10;while(OI_top--)pc(OI_USE[OI_top+1]+'0');return;}
void writec(char c[]){int len=strlen(c);for(int i=0;i<len;i++)pc(c[i]);}
void writes(string s){int len=s.length();for(int i=0;i<len;i++)pc(s[i]);}
void readc(char &c,int l,int r){c=gc(); while(c!=EOF&&(c<l||c>r)) c=gc();}
void readc(char &c,char val){c=gc();while(c!=EOF&&c!=val) c=gc();}
void readc(char val){char c;c=gc();while(c!=EOF&&c!=val) c=gc();}
void readls(string &s){char c=gc();while(c!='\n') s.push_back(c),c=gc();}
Ts void read(Ty &x,Ar &...y) {read(x),read(y...);}
Tp void writeln(Ty x) {write(x),pc('\n');}
Tp void writesp(Ty x) {write(x),pc(' ');}
#undef Ts
#undef Tp
} using namespace WrongIO;
struct awa{
vector<ll> s;
ll s1,s2;
ll num,kind,len;
void clear()
{
s.clear(); num=0; kind=0;
s1=s2=-1; len=0;
}
}e[1000050];
ll T,n;
int main()
{
read(T);
while(T--)
{
read(n);
rep(i,1,n)
{
e[i].clear();
ll opt; read(opt);
if(opt==1)
{
ll m; read(m); e[i].len=m;
rep(j,1,m)
{
ll tp; read(tp);// dbg(tp); dbg(e[i].s.size());
if(e[i].num==0)
{
e[i].num=1,e[i].kind=tp;
}else{
if(e[i].kind==tp) e[i].num++; else e[i].num--;
}
// dbg(e[i].num);
e[i].s.push_back(tp);
}
}
if(opt==2)
{
read(e[i].s1,e[i].s2);
ll t1=e[i].s1,t2=e[i].s2;
if(e[t1].kind==e[t2].kind)
{
e[i].num=e[t1].num+e[t2].num;
e[t1].kind=e[t2].kind;
}else{
if(e[t1].num<e[t2].num) swap(t1,t2);
e[i].kind=e[t1].kind;
e[i].num=e[t1].num-e[t2].num;
}
e[i].len=e[t1].len+e[t2].len;
}
}
ll kd=e[n].kind;
rep(i,1,n)
{
e[i].num=0;
if(e[i].s1==-1)
{
for(ll j=0;j<e[i].len;j++)
{
ll tp=e[i].s[j];
// dbg(tp);
if(tp==kd) e[i].num++;
}
}else e[i].num=e[e[i].s1].num+e[e[i].s2].num;
}
// rep(i,1,n)
// {
// dbg(i); dbg(e[i].kind); dbg(e[i].num);
// }
if(n>=5) writesp(e[n].len),writesp(e[n].num);
if(e[n].num>e[n].len/2) writeln(2*(e[n].len-e[n].num));
else writeln(e[n].len);
}
}
//g++ .Yuria.cpp -o rst -std=c++17
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 14ms
memory: 66080kb
input:
2 1 1 5 3 3 2 1 3 3 1 3 3 3 2 1 4 2 2 3 3 2 1 2
output:
4 6
result:
ok 2 lines
Test #2:
score: -100
Wrong Answer
time: 83ms
memory: 66168kb
input:
10000 100 1 30 371028678 371028678 371028678 716418076 398221499 591504380 398221499 398221499 591504380 777141390 398221499 591504380 591504380 777141390 287847807 716418076 777141390 716418076 777141390 287847807 287847807 287847807 371028678 371028678 398221499 777141390 371028678 6827702 6827702...
output:
700 0 700 68 0 68 332 11 332 311 0 311 131 26 131 1048 0 1048 194 19 194 667 0 667 754 0 754 640 0 640 532 0 532 252 30 252 35 0 35 351 0 351 1228 0 1228 238 0 238 1025 0 1025 354 0 354 383 0 383 571 0 571 4272 0 4272 340 0 340 1044 0 1044 199 27 199 448 0 448 190 0 190 1459 0 1459 69 7 69 841 0 841...
result:
wrong answer 1st lines differ - expected: '700', found: '700 0 700'