QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#141814 | #4564. Digital Circuit | AbdelmagedNour | 0 | 39ms | 8936kb | C++20 | 2.3kb | 2023-08-18 01:43:51 | 2023-08-18 01:51:10 |
Judging History
answer
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast,unroll-loops")
#include <immintrin.h>
#pragma GCC target("avx512vl,bmi,bmi2,lzcnt,popcnt")
using namespace std;
typedef __m512i vi;
typedef unsigned long long ull;
#include "circuit.h"
const int MAX=200025,mod=(1e9)+2022;
int cont[MAX],val[MAX],state[MAX],n,m;
unsigned long long State[MAX/64+1];
vi Cont[MAX/16+2];
vector<vector<int>>adj;
void dfs(int v){
if(v>=n){
val[v]=1;
return;
}
int sz=adj[v].size();
val[v]=sz;
for(auto&u:adj[v]){
dfs(u);
val[v]=(val[v]*1LL*val[u])%mod;
}
}
void dfs(int v,int cur){
if(v>=n){
cont[v-n]=cur;
return;
}
int sz=adj[v].size();
int pre[sz],suf[sz];
for(int i=0;i<sz;i++)suf[i]=pre[i]=val[adj[v][i]];
for(int i=1;i<sz;i++)pre[i]=(pre[i]*1LL*pre[i-1])%mod;
for(int i=sz-2;i>=0;i--)suf[i]=(suf[i]*1LL*suf[i+1])%mod;
for(int i=0;i<sz;i++){
int nw=cur;
if(i)nw=(nw*1LL*pre[i-1])%mod;
if(i+1<sz)nw=(nw*1LL*suf[i+1])%mod;
dfs(adj[v][i],nw);
}
}
void init(int N,int M,vector<int>P,vector<int>A){
n=N;m=M;
adj.resize(N+M);
for(int i=1;i<N+M;i++)adj[P[i]].push_back(i);
for(int i=0;i<M;i++)state[i]=A[i];
dfs(0);
dfs(0,1);
for(int i=0;i<M;i++)State[i>>6]|=(((ull)state[i])<<(i&63));
for(int i=0;i<M;i+=16)Cont[i>>6]=_mm512_loadu_si512((vi*)&cont[i]);
}
int count_ways(int L, int R) {
L-=n;R-=n;
int bl=(L>>6),br=(R>>6);
if(bl==br){
ull mask=(1ULL<<(R&63))-(1ULL<<(L&63));
mask+=(1ULL<<(R&63));
State[bl]^=mask;
}else{
ull mask=ULLONG_MAX - ((1ULL<<L)-1);
State[bl]^=mask;bl++;
mask=(2ULL<<(R&63)) - 1;
State[br]^=mask;
for(int i=bl;i<br;i++)State[i]^=ULLONG_MAX;
}
vi ans=_mm512_setzero_epi32(),temp;
vi MOD=_mm512_set1_epi32(mod);
vi zero=_mm512_setzero_epi32();
int sz=(m-1)>>16;
for(int i=0;i<=sz;i++){
ans=_mm512_add_epi32(ans,_mm512_mask_blend_epi32((State[i>>2]>>((i&3)*16))&UINT16_MAX,Cont[i],zero));
temp=_mm512_sub_epi32(ans,MOD);
ans=_mm512_mask_blend_epi32(_mm512_cmpge_epi32_mask(ans,MOD),ans,temp);
}
int arr[16]={};
_mm512_storeu_si512((vi*)arr,ans);
return accumulate(arr,arr+16,0LL)%mod;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3776kb
input:
1 2 -1 0 0 0 0 1 1 2 2 1 2 2 2 1 2 -1 -1 -2 -2
output:
1 0 2 1 1
result:
wrong answer 4th lines differ - expected: '2', found: '0'
Subtask #2:
score: 0
Wrong Answer
Test #9:
score: 0
Wrong Answer
time: 1ms
memory: 3712kb
input:
1 2 -1 0 0 0 0 1 1 2 2 1 2 2 2 1 2 -1 -1 -2 -2
output:
1 0 2 1 1
result:
wrong answer 4th lines differ - expected: '2', found: '0'
Subtask #3:
score: 0
Skipped
Dependency #1:
0%
Subtask #4:
score: 0
Wrong Answer
Test #43:
score: 0
Wrong Answer
time: 39ms
memory: 8936kb
input:
32767 32768 -1 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50...
output:
336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 336599136 ...
result:
wrong answer 3rd lines differ - expected: '431985922', found: '336599136'
Subtask #5:
score: 0
Skipped
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #2:
0%
Subtask #7:
score: 0
Skipped
Dependency #3:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%