QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#309662 | #8133. When Anton Saw This Task He Reacted With 😩 | ucup-team191# | TL | 3793ms | 20360kb | C++14 | 3.7kb | 2024-01-20 19:39:00 | 2024-01-20 19:39:00 |
Judging History
answer
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
using ll=long long;
using pii=pair<int,int>;
using vi=vector<int>;
using vl=vector<ll>;
using vec=array<int,3>;
using mat=array<vec,3>;
#define pb push_back
#define all(a) begin(a),end(a)
const int N=200010,MOD=998244353,K=300;
const char en='\n';
const ll LLINF=1ll<<60;
int sub(int a,int b)
{
if (a>=b) return a-b;
return a-b+MOD;
}
int mul(int a,int b)
{
return a*1ll*b%MOD;
}
void ad(int&a,int b)
{
a+=b;
if (a>=MOD) a-=MOD;
}
vec sub(vec a,vec b)
{
return {sub(a[0],b[0]),sub(a[1],b[1]),sub(a[2],b[2])};
}
vec mul(mat a,vec b)
{
vec re;
for (int i=0;i<3;++i)
{
re[i]=0;
for (int k=0;k<3;++k)
{
ad(re[i],mul(a[i][k],b[k]));
}
}
return re;
}
vec mul(vec a,int b)
{
return {mul(a[0],b),mul(a[1],b),mul(a[2],b)};
}
vec cross(vec a,vec b)
{
return {sub(mul(a[1],b[2]),mul(a[2],b[1])),sub(mul(a[2],b[0]),mul(a[0],b[2])),sub(mul(a[0],b[1]),mul(a[1],b[0]))};
}
mat crossL(mat a,vec b)
{
return {sub(mul(a[1],b[2]),mul(a[2],b[1])),sub(mul(a[2],b[0]),mul(a[0],b[2])),sub(mul(a[0],b[1]),mul(a[1],b[0]))};
}
mat crossR(vec a,mat b)
{
return {sub(mul(b[2],a[1]),mul(b[1],a[2])),sub(mul(b[0],a[2]),mul(b[2],a[0])),sub(mul(b[1],a[0]),mul(b[0],a[1]))};
}
int n,q,lc[N],rc[N],ind[N],de[N],r[N],par[20][N];
bool impo[N];
vec va[N];
vi ord,vaz;
pair<int,mat> tra[N];
mat id;
void dfs1(int i)
{
ind[i]=ord.size();
ord.pb(i);
if (lc[i]!=-1)
{
par[0][lc[i]]=i;
de[lc[i]]=de[i]+1;
dfs1(lc[i]);
par[0][rc[i]]=i;
de[rc[i]]=de[i]+1;
dfs1(rc[i]);
}
r[i]=ord.size();
}
void dfs2(int i)
{
if (impo[i])
{
tra[i]={i,id};
vaz.pb(i);
return;
}
if (lc[i]==-1)
{
tra[i].x=-1;
tra[i].y[0]=va[i];
return;
}
dfs2(lc[i]);
dfs2(rc[i]);
if (!impo[lc[i]] && !impo[rc[i]])
{
tra[i].x=-1;
tra[i].y[0]=cross(tra[lc[i]].y[0],tra[rc[i]].y[0]);
return;
}
impo[i]=1;
if (impo[lc[i]] && impo[rc[i]])
{
tra[i]={i,id};
vaz.pb(i);
return;
}
if (impo[lc[i]] && !impo[rc[i]])
{
tra[i].x=tra[lc[i]].x;
tra[i].y=crossL(tra[lc[i]].y,tra[rc[i]].y[0]);
return;
}
if (!impo[lc[i]] && impo[rc[i]])
{
tra[i].x=tra[rc[i]].x;
tra[i].y=crossR(tra[lc[i]].y[0],tra[rc[i]].y);
return;
}
assert(0);
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
for (int i=0;i<3;++i) id[i][i]=1;
par[0][1]=1;
cin>>n>>q;
for (int i=1;i<=n;++i)
{
char ti;
cin>>ti;
if (ti=='x')
{
cin>>lc[i]>>rc[i];
}
else
{
cin>>va[i][0]>>va[i][1]>>va[i][2];
lc[i]=-1;
rc[i]=-1;
}
}
dfs1(1);
//cout<<"dfs-ed"<<endl;
vector<pair<int,vec>> qu;
for (int r=0;r<q;++r)
{
int x1,a1,b1,c1;
cin>>x1>>a1>>b1>>c1;
qu.pb({x1,{a1,b1,c1}});
if (qu.size()==K || r==q-1)
{
memset(impo,0,sizeof(impo));
for (auto x: qu) impo[x.x]=1;
vaz.clear();
dfs2(1);
/*cout<<"----"<<en;
cout<<vaz.size()<<en;
for (auto x: vaz) cout<<x<<' ';
cout<<en;
cout<<"----"<<en;*/
for (auto x: qu)
{
va[x.x]=x.y;
for (auto i: vaz)
{
if (lc[i]==-1) continue;
vec lij=mul(tra[lc[i]].y,va[tra[lc[i]].x]);
vec des=mul(tra[rc[i]].y,va[tra[rc[i]].x]);
va[i]=cross(lij,des);
}
if (vaz.back()!=1)
{
vec lij,des;
if (impo[lc[1]])
{
lij=mul(tra[lc[1]].y,va[tra[lc[1]].x]);
des=tra[rc[1]].y[0];
}
else
{
assert(impo[rc[1]]);
lij=tra[lc[1]].y[0];
des=mul(tra[rc[1]].y,va[tra[rc[1]].x]);
}
va[1]=cross(lij,des);
}
cout<<va[1][0]<<' '<<va[1][1]<<' '<<va[1][2]<<en;
}
qu.clear();
}
}
}
詳細信息
Test #1:
score: 100
Accepted
time: 2ms
memory: 14044kb
input:
5 3 x 2 3 v 1 0 1 x 4 5 v 0 2 1 v 1 1 1 4 1 2 3 5 0 1 1 4 0 2 2
output:
998244351 0 2 1 998244351 998244352 0 0 0
result:
ok 9 numbers
Test #2:
score: 0
Accepted
time: 3793ms
memory: 20360kb
input:
199999 100000 x 137025 65661 v 572518668 158967010 74946561 x 129836 192657 x 141948 187810 v 574918069 328924434 141474729 x 143312 111002 x 52772 148497 v 922857701 690080961 651915759 v 656198340 28002884 129579416 v 639893144 265359784 646791226 v 796871409 411409966 598676495 v 882562617 224394...
output:
393120558 773766615 387297348 759959566 981774500 128012497 294611811 980011608 533642029 404379574 745296852 53493560 404565501 828869760 78021156 592494858 647751304 881427733 190018467 515243135 518180555 628180500 509984554 257430135 13737245 352087791 917410487 932051309 366591227 479931477 199...
result:
ok 300000 numbers
Test #3:
score: -100
Time Limit Exceeded
input:
199999 100000 x 154525 80092 v 450407262 725458410 590777520 x 24720 135901 v 719242117 114943104 186796011 v 382530926 89156744 943939337 x 183376 26042 x 109984 157873 x 151637 150600 x 4115 27454 x 163135 92648 x 16764 33212 v 849210403 945083972 689295397 v 471196117 68587428 225597765 x 24643 5...
output:
677067461 996514296 449166851 810403092 258196842 853459733 410756156 253348518 912664471 327134890 519245783 922528759 317367558 536888537 506214109 484753530 879045782 772404948 422920052 152084658 517340457 1207902 348787162 320821077 776293878 699474926 711114530 871858473 468497588 822120121 24...