QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#290927 | #7839. 虹 | zhouhuanyi | 10 | 23ms | 129052kb | C++20 | 1.7kb | 2023-12-25 21:19:46 | 2023-12-25 21:19:46 |
Judging History
answer
#include<iostream>
#include<cstdio>
#include<vector>
#include<bitset>
#include<cmath>
#define N 1000
#define M 1000
using namespace std;
const int sz=512;
int read()
{
char c=0;
int sum=0;
while (c<'0'||c>'9') c=getchar();
while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
return sum;
}
int gcd(int x,int y)
{
if (!y) return x;
return gcd(y,x%y);
}
int n,q,sl,sr,leng,block[N+1],w[N+1],depth[N+1],ans[N+1],lg[N+1],st[N+1],tong[N+1],length,op[N+1],l[N+1],r[N+1],u[N+1],fa[N+1][21];
bool z[N+1],nprime[N+1],used[N+1];
vector<int>E[N+1];
vector<int>p[N+1];
bitset<M+1>B[N+1][N+1];
bitset<M+1>rst;
void add(int x,int y)
{
E[x].push_back(y),E[y].push_back(x);
return;
}
void dfs(int rt,int x)
{
used[x]=1,B[rt][x][x]=1;
for (int i=0;i<E[x].size();++i)
if (!used[E[x][i]])
B[rt][E[x][i]]=B[rt][x],dfs(rt,E[x][i]);
return;
}
int main()
{
int x,y,szt,cnt;
n=read(),q=read(),szt=sqrt(n);
for (int i=2;i<=N;++i) lg[i]=lg[i>>1]+1;
for (int i=1;i<=n;++i) z[i]=read()&1,block[i]=(i-1)/szt+1;
for (int i=1;i<=n-1;++i) x=read(),y=read(),add(x,y);
for (int i=1;i<=n;++i)
{
for (int j=1;j<=n;++j) used[j]=0;
dfs(i,i);
}
for (int i=1;i<=lg[n];++i)
for (int j=1;j<=n;++j)
fa[j][i]=fa[fa[j][i-1]][i-1];
for (int i=1;i<=q;++i)
{
op[i]=read();
if (op[i]==1)
{
l[i]=read(),r[i]=read(),rst.reset();
if (l[i]==r[i]) rst[l[i]]=1;
else
{
for (int j=l[i];j<=r[i]-1;++j) rst|=B[j][j+1];
}
for (int j=1;j<=n;++j) w[j]^=rst[j];
}
else
{
l[i]=read(),r[i]=read(),u[i]=read(),cnt=0;
for (int j=l[i];j<=r[i];++j) cnt+=(z[gcd(u[i],j)]&w[j]);
printf("%lld\n",(19901990ll*cnt+r[i]-l[i]+1)%20242024);
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 10
Accepted
Test #1:
score: 10
Accepted
time: 23ms
memory: 129044kb
input:
998 1000 955556485 952505211 899166521 258704448 894183248 636280051 62949347 983956660 113872828 588367167 208142006 665025449 944228063 284736189 169202015 56096447 404419923 30158095 111191865 717455344 790159420 391379127 208279658 426780799 886604643 940903663 618716147 773652834 385881251 1593...
output:
16521790 13341944 16841705 2220375 880451 3621051 12662029 6300750 3240463 2400556 6501168 3580517 9221391 8381420 12982211 8001004 9361122 17262479 3600913 10401408 16202143 15022309 16341874 7861442 1560390 8340899 12421304 13961591 10421679 12101636 17361912 11781615 4780673 13641787 20102392 171...
result:
ok 490 lines
Test #2:
score: 0
Accepted
time: 21ms
memory: 129048kb
input:
1000 997 103470799 773962597 977631665 55926526 616833039 263471628 825848455 638144717 340710593 68036397 623497249 808915869 345157828 256095693 400262335 173843004 238983751 646376872 243739767 221162275 465477137 772061029 840064611 274062983 522264159 689460088 20129595 287189331 622217799 6948...
output:
13621441 17282360 11241382 15841876 17222347 1880319 12441746 10381083 18222171 7341024 10081427 2900456 2900406 13801602 17521768 19901997 8521022 13281468 2400503 17201967 19942477 14461494 19742168 14461471 12121799 2600806 18902095 1941004 19901993 10221200 8901579 9201080 19442423 720422 130019...
result:
ok 527 lines
Test #3:
score: 0
Accepted
time: 18ms
memory: 129052kb
input:
1000 1000 1697351 841785432 606301324 899151762 398181773 419939453 419455373 826820357 965555426 240847697 718049384 378823565 364137136 867089279 445499605 934770217 134914678 642584637 766848023 203338778 153291975 240768524 446186401 462123008 408740063 755064293 274502953 646610365 27815415 164...
output:
368 198 7021295 16001721 18602311 8021119 17201976 1380573 13141934 3580444 14641604 16681966 3240524 16182225 7541265 8520964 6341385 18922654 17861873 13781440 11581327 14342249 3600640 6821000 16841702 860350 16501686 3420674 18881910 6161028 17022054 3920543 4600572 6300810 3761005 11401360 8181...
result:
ok 502 lines
Subtask #2:
score: 0
Runtime Error
Test #4:
score: 0
Runtime Error
input:
65531 65535 968854923 932574892 192297572 866236747 654755663 148562561 273214896 947434573 938626677 992982166 219888853 229840279 676071061 383387319 372883953 729287797 601010887 31942080 990584163 823724544 181337075 918252129 896876911 768539961 357780649 890577681 819641335 320266037 55445939 ...
output:
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%