QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#692869 | #9115. Contour Multiplication | icpc_zhzx034# | ML | 0ms | 0kb | C++14 | 3.4kb | 2024-10-31 15:08:52 | 2024-10-31 15:09:16 |
answer
#include<bits/stdc++.h>
using namespace std;
#define il inline
#define fi first
#define se second
#define mk make_pair
#define eb emplace_back
#define rep(i,l,r) for(int i=(l); i<=(r); ++i)
#define rep_(i,l,r) for(int i=(l); i>=(r); --i)
typedef long long lr;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
constexpr int mod1=998244353,mod2=1e9+7;
constexpr db pi=3.141592653589793,eps=1e-9;
constexpr int inf32=0x3f3f3f3f,Inf32=0xc0c0c0c0;
constexpr lr inf64=0x3f3f3f3f3f3f3f3f,Inf64=0xc0c0c0c0c0c0c0c0;
template<typename T>il T Max(T x,T y) { return (x>y)? x:y; }
template<typename T>il T Min(T x,T y) { return (x<y)? x:y; }
template<typename T>il T gcd(T x,T y) { return (!y)? x:gcd(y,x%y); }
template<typename T>il T Abs(T x) { return (x>0)? x:(-x); }
template<typename T>il T Rnd(T l,T r,mt19937_64 &eng)
{
uniform_int_distribution<T> uid(l,r);
return uid(eng);
}
mt19937_64 eng(chrono::high_resolution_clock::now().time_since_epoch().count());
constexpr int N=1<<18;
struct bp
{
int num,mul;
bp() {}
bp(int Num,int Mul) { num=Num,mul=Mul; }
};
vector<bp> v[N<<2][19],w[N<<2][19][2];
int n,m,k,a[N];
il void Build(int k,int l,int r,int dep)
{
if(k>1)
rep(i,0,dep)
{
int sz0=w[k][i][0].size(),sz1=w[k][i][1].size();
int lnum=-1,lmul=-1,c0=0,c1=0;
while(c0<sz0&&c1<sz1)
{
bp cur0=w[k][i][0][c0],cur1=w[k][i][1][c1];
if(cur0.num<=cur1.num)
{
if(lnum==cur0.num)
lmul=(lr)lmul*cur0.mul%m;
else
{
if(lnum!=-1&&lmul!=-1)
v[k][i].eb((bp){lnum,lmul});
lnum=cur0.num,lmul=cur0.mul;
}
++c0;
}
else
{
if(lnum==cur1.num)
lmul=(lr)lmul*cur1.mul%m;
else
{
if(lnum!=-1&&lmul!=-1)
v[k][i].eb((bp){lnum,lmul});
lnum=cur1.num,lmul=cur1.mul;
}
++c1;
}
}
while(c0<sz0)
{
bp cur0=w[k][i][0][c0];
if(lnum==cur0.num)
lmul=(lr)lmul*cur0.mul%m;
else
{
if(lnum!=-1&&lmul!=-1)
v[k][i].eb((bp){lnum,lmul});
lnum=cur0.num,lmul=cur0.mul;
}
++c0;
}
while(c1<sz1)
{
bp cur1=w[k][i][1][c1];
if(lnum==cur1.num)
lmul=(lr)lmul*cur1.mul%m;
else
{
if(lnum!=-1&&lmul!=-1)
v[k][i].eb((bp){lnum,lmul});
lnum=cur1.num,lmul=cur1.mul;
}
++c1;
}
if(lnum!=-1&&lmul!=-1)
v[k][i].eb((bp){lnum,lmul});
}
if(l==r)
{
a[l]=1;
for(bp i:v[k][0])
a[l]=(lr)a[l]*i.mul%m;
return;
}
rep(i,0,dep)
for(bp j:v[k][i])
{
if(!(j.num&(1<<(dep-1))))
{
if(i<dep)
w[k<<1][i][0].eb(j);
if(i)
w[k<<1|1][i-1][1].eb(j);
}
else
{
if(i)
w[k<<1][i-1][1].eb((bp){j.num^(1<<(dep-1)),j.mul});
if(i<dep)
w[k<<1|1][i][0].eb((bp){j.num^(1<<(dep-1)),j.mul});
}
}
int mid=(l+r)>>1;
Build(k<<1,l,mid,dep-1),Build(k<<1|1,mid+1,r,dep-1);
}
il void Solve()
{
cin>>n>>m>>k;
rep(i,1,k)
{
int x,y,z; cin>>x>>y>>z;
v[1][y].eb((bp){x,z});
}
Build(1,0,(1<<n)-1,n);
rep(i,0,(1<<n)-1)
cout<<a[i]<<' ';
cout<<'\n';
}
int main()
{
#ifdef LOCAL
string fpre="test",isuf="in",osuf="out";
assert(freopen((fpre+"."+isuf).c_str(),"r",stdin));
assert(freopen((fpre+"."+osuf).c_str(),"w",stdout));
#endif
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
int T=1;
while(T--)
Solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 0
Memory Limit Exceeded
input:
3 100 2 0 2 4 3 0 25
output:
1 1 1 0 1 4 4 1