QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#688949 | #3840. Pass the Ball! | DepletedPrism# | WA | 8ms | 22328kb | C++17 | 4.1kb | 2024-10-30 14:29:03 | 2024-10-30 14:29:03 |
Judging History
answer
/*
* @Author: zxxzy
* @Date: 2024-10-28 22:26:06
*/
#include <iostream>
#include <algorithm>
#include <cstring>
#include <bitset>
#include <set>
#include <cmath>
#include <vector>
#include <map>
//#define int long long
#define space ' '
#define endl '\n'
#define de(x) cout<<"** "<<x<<" **"<<endl;
#define N 200005
using namespace std;
// using ll = long long;
using ll=__int128;
const ll mod =1231453023109121;
const int INF = 0x3f3f3f3f;
const double eps = 1e-6;
const int G=3;
int rev[(1<<19)+5];
ll ww[2][(1<<19)+5];
ll ppow(ll a,ll b){
ll res=1;
while(b){
if(b&1)res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
void prentt(){
int len=1<<19;
for(int i=1;i<len;i<<=1){
ll wka=ppow(G,(mod-1)/(i<<1));
ll wkb=ppow(wka,mod-2);
ll wnka=1,wnkb=1;
for(int k=0;k<i;k++){
ww[0][i+k]=wnka;
wnka=wnka*wka%mod;
ww[1][i+k]=wnkb;
wnkb=wnkb*wkb%mod;
}
}
}
void ntt(vector<ll> &a,int len,int on){
ll *w=(on==1?ww[0]:ww[1]);
for(int i=0;i<len;i++)if(i<rev[i])swap(a[i],a[rev[i]]);
for(int i=1;i<len;i<<=1){
for(int j=0;j<len;j+=(i<<1)){
for(int k=0;k<i;k++){
ll x=a[j+k],y=w[i+k]*a[i+j+k]%mod;
a[j+k]=(x+y)%mod;
a[i+j+k]=(x-y+mod)%mod;
}
}
}
if(on==-1){
ll inv=ppow(len,mod-2);
for(int i=0;i<len;i++){
a[i]=a[i]*inv%mod;
}
}
}
vector<ll> polymul(vector<ll> a,int n,vector<ll> b,int m){
int len=1,k=0;
while(len<=m+n)len<<=1,k++;
for(int i=0;i<len;i++){
rev[i]=(rev[i>>1]>>1)|((i&1)<<(k-1));
}
a.resize(len);
b.resize(len);
ntt(a,len,1);
ntt(b,len,1);
for(int i=0;i<len;i++)a[i]=a[i]*b[i]%mod;
ntt(a,len,-1);
a.resize(n+m+1);
return a;
}
signed main() {
#ifdef LOCAL
freopen("D:\\code2023\\test\\input.txt", "r", stdin);
freopen("D:\\code2023\\test\\output.txt", "w", stdout);
#endif
std::ios::sync_with_stdio(false);
cin.tie(0);
prentt();
int n,q;
cin>>n>>q;
vector<int> p(n+1);
for(int i=1;i<=n;i++){
cin>>p[i];
}
vector<int> vis(n+1);
vector<vector<ll>> xunhuan;
for(int i=1;i<=n;i++){
if(!vis[i]){
vector<ll> tmp;
int now=i;
while(p[now]!=i){
tmp.push_back(now);
vis[now]=1;
now=p[now];
}
vis[now]=1;
tmp.push_back(now);
xunhuan.push_back(tmp);
// for(int ss:tmp)cout<<ss<<space;cout<<endl;
}
}
vector<vector<long long>> zhongjian;
for(auto &vec:xunhuan){
int nn=vec.size();
vector<ll> tmp=vec;
reverse(tmp.begin(),tmp.end());
for(int i=0;i<nn;i++){
vec.push_back(vec[i]);
}
vector<ll> f=polymul(vec,2*nn-1,tmp,nn-1);
// for(int ss:vec)cout<<ss<<space;cout<<endl;
// for(int ss:tmp)cout<<ss<<space;cout<<endl;
vector<long long> fans;
for(int j=nn-1;j<=2*nn-2;j++){
fans.push_back(f[j]);
}
// for(int ss:fans)cout<<ss<<space;cout<<endl;
zhongjian.push_back(fans);
}
sort(zhongjian.begin(), zhongjian.end(), [](vector<long long> &a, vector<long long> &b) {
return a.size() < b.size();
});
vector<vector<long long>> finalans;
for(int i=0;i<zhongjian.size();i++){
int now=i;
vector<long long> h=zhongjian[i];
if(now+1<zhongjian.size()&&zhongjian[now].size()==zhongjian[now+1].size()){
for(int j=0;j<h.size();j++){
h[j]+=zhongjian[now+1][j];
}
now++;
}
i=now;
finalans.push_back(h);
}
while(q--){
long long ans=0;
int k;
cin>>k;
for(auto &vec:finalans){
int nn=vec.size();
k%=nn;
ans+=vec[k];
}
cout<<ans<<endl;
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 4ms
memory: 20940kb
input:
4 4 2 4 1 3 1 2 3 4
output:
25 20 25 30
result:
ok 4 lines
Test #2:
score: 0
Accepted
time: 8ms
memory: 21716kb
input:
3 6 2 3 1 1 2 3 999999998 999999999 1000000000
output:
11 11 14 11 14 11
result:
ok 6 lines
Test #3:
score: 0
Accepted
time: 3ms
memory: 20484kb
input:
3 6 3 1 2 1 2 3 999999998 999999999 1000000000
output:
11 11 14 11 14 11
result:
ok 6 lines
Test #4:
score: 0
Accepted
time: 4ms
memory: 22108kb
input:
1000 10000 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100...
output:
333334000 332835500 332338000 331841500 331346000 330851500 330358000 329865500 329374000 328883500 328394000 327905500 327418000 326931500 326446000 325961500 325478000 324995500 324514000 324033500 323554000 323075500 322598000 322121500 321646000 321171500 320698000 320225500 319754000 319283500 ...
result:
ok 10000 lines
Test #5:
score: -100
Wrong Answer
time: 4ms
memory: 22328kb
input:
1000 10000 187 493 316 665 124 40 448 649 657 65 438 730 816 107 789 286 309 469 169 216 488 52 212 111 541 83 990 48 282 867 36 220 676 241 959 372 322 244 481 708 595 957 215 223 120 658 291 176 229 158 431 492 221 986 889 861 606 518 106 349 410 765 745 812 563 998 150 392 358 328 747 793 587 507...
output:
251369964 249241618 252521867 248625671 245544165 253890141 253936179 250805268 253504811 333833500 248625671 250941165 250805268 251395304 252832040 253936179 248625671 251395304 245871243 249456638 245544165 251369964 248101019 252295342 250891718 247713972 245544165 250891718 248101019 252832040 ...
result:
wrong answer 1st lines differ - expected: '250347169', found: '251369964'