QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#167155 | #1851. Directed Acyclic Graph | Crysfly | AC ✓ | 799ms | 220168kb | C++17 | 6.1kb | 2023-09-07 10:55:56 | 2023-09-07 10:55:56 |
Judging History
answer
#include <algorithm>
#include <iostream>
#include <climits>
#include <bitset>
#include <cstdio>
#include <cctype>
#include <queue>
#include <cmath>
using namespace std;
inline int read()
{
int x=0,f=1;
char ch=getchar();
while (!isdigit(ch)) f=ch=='-'?-1:f,ch=getchar();
while (isdigit(ch)) x=x*10+ch-'0',ch=getchar();
return x*f;
}
int buf[30];
inline void write(int x)
{
if (x<0) putchar('-'),x=-x;
for (;x;x/=10) buf[++buf[0]]=x%10;
if (!buf[0]) buf[++buf[0]]=0;
for (;buf[0];putchar('0'+buf[buf[0]--]));
}
const int INF=INT_MAX/2;
const int N=100005;
const int M=100005;
const int Q=100005;
const int MAXA=350;
const int MAXB=2200;
const int MAXC=12000;
int last[N],deg[N],kth[N];
int tov[M],nxt[M];
int opt[Q][3];
int answer[Q];
int n,m,q,tot,idx;
queue<int> que;
inline void insert(int x,int y){tov[++tot]=y,nxt[tot]=last[x],last[x]=tot;}
/*
Partition the point set
*/
bitset<MAXC> con[N];
int C;
inline void Partition_Point_Set();
inline void Process_Connectedness(int l,int r);
inline void Solve_Query(int l,int r);
/*
Partition the queries of the second type
*/
int stt[MAXA],ent[MAXA];
int f[MAXA][N];
int srt[MAXA];
int mintag[N];
int op[Q][3];
int A,cnt;
inline void Partition_Operation();
inline void Process_Block(int bid,int l,int r);
inline int Query_Range(int l,int x,int st,int en);
/*
Periodic Reconstruction (the queries of the first type)
*/
int cache[MAXB][2];//time point
int asstag[N];//time value
int csize;
int B,btot;
inline void Initialization();
inline void Add_Operation(int id);
inline int Latest_Modification(int l,int x);
inline void Reconstruction();
void pre()
{
idx=0;
for (int x=1;x<=n;++x) if (!deg[x]) que.push(x);
for (int x;!que.empty();)
{
kth[++idx]=x=que.front(),que.pop();
for (int i=last[x],y;i;i=nxt[i])
if (!--deg[y=tov[i]]) que.push(y);
}
}
int main()
{
//freopen("destiny.in","r",stdin),freopen("destiny.out","w",stdout);
n=read(),m=read(),q=read();
for (int i=1,x,y;i<=m;++i) x=read(),y=read(),insert(x,y),++deg[y];
pre();
for (int i=1;i<=q;++i)
{
opt[i][0]=read(),opt[i][1]=read();
if (opt[i][0]!=3) opt[i][2]=read();
}
Partition_Operation(),Partition_Point_Set();
for (int i=1;i<=q;++i) if (opt[i][0]==3) write(answer[i]),putchar('\n');
fclose(stdin),fclose(stdout);
return 0;
}
/*----------------------------------------------------------------------------*/
inline void Partition_Operation()
{
for (int i=1;i<=q;++i) if (opt[i][0]==2) op[++cnt][0]=i,op[cnt][1]=opt[i][1],op[cnt][2]=opt[i][2];
A=trunc(sqrt(cnt))+1,btot=0;
for (int lcur=1,rcur;lcur<=cnt;lcur=rcur+1)
{
rcur=min(lcur+A-1,cnt);
stt[++btot]=op[lcur][0],ent[btot]=op[rcur][0];
Process_Block(btot,lcur,rcur);
}
}
inline bool cmp(int x,int y){return op[x][2]<op[y][2]||op[x][2]==op[y][2]&&op[x][0]>op[y][0];}
inline void Process_Block(int bid,int l,int r)
{
for (int i=1;i<=n;++i) mintag[i]=INF;
int tmp=0;
for (int i=l;i<=r;++i) srt[++tmp]=i;
sort(srt+1,srt+1+tmp,cmp);
for (int j=1,x,tag;j<=tmp;++j)
{
if (mintag[x=op[srt[j]][1]]<=(tag=op[srt[j]][2])) continue;
for (mintag[x]=tag,que.push(x);!que.empty();)
{
x=que.front(),que.pop();
for (int i=last[x],y;i;i=nxt[i])
if (mintag[y=tov[i]]>tag) mintag[y]=tag,que.push(y);
}
}
for (int i=1;i<=n;++i) f[bid][i]=mintag[i];
}
inline int Query_Range(int l,int x,int st,int en)
{
int ret=INF;
for (int i=1,lcur=1,rcur;i<=btot;++i,lcur=rcur+1)
{
rcur=min(lcur+A-1,cnt);
if (ent[i]<st) continue;
if (stt[i]>en) break;
if (stt[i]<=st)
{
for (int j=lcur;j<=rcur;++j)
if (st<=op[j][0]&&op[j][0]<=en&&con[op[j][1]].test(x-l+1))
ret=min(ret,op[j][2]);
continue;
}
if (en<=ent[i])
{
for (int j=lcur;j<=rcur;++j)
if (op[j][0]<=en&&con[op[j][1]].test(x-l+1))
ret=min(ret,op[j][2]);
continue;
}
ret=min(ret,f[i][x]);
}
return ret;
}
/*----------------------------------------------------------------------------*/
inline void Partition_Point_Set()
{
C=30*trunc(sqrt(n))+1;
for (int lcur=1,rcur;lcur<=n;lcur=rcur+1)
{
rcur=min(lcur+C-1,n);
Process_Connectedness(lcur,rcur),Solve_Query(lcur,rcur);
}
}
inline void Process_Connectedness(int l,int r)
{
for (int x=1;x<=n;++x) con[x].reset();
for (int j=n,x;j>=1;--j)
{
x=kth[j];
if (l<=x&&x<=r) con[x].set(x-l+1);
for (int i=last[x];i;i=nxt[i]) con[x]|=con[tov[i]];
}
}
inline void Solve_Query(int l,int r)
{
Initialization();
for (int i=1;i<=q;++i)
if (opt[i][0]==1) Add_Operation(i);
else if (opt[i][0]==3&&l<=opt[i][1]&&opt[i][1]<=r)
{
int x=opt[i][1],lpass=Latest_Modification(l,x),mintg=Query_Range(l,x,lpass,i);
answer[i]=min(opt[lpass][2],mintg);
}
}
/*----------------------------------------------------------------------------*/
inline void Initialization()
{
B=trunc(pow(q,2./3.))+1,csize=0;
for (int i=1;i<=n;++i) asstag[i]=0;
}
inline void Add_Operation(int id)
{
cache[++csize][0]=id,cache[csize][1]=opt[id][1];
if (csize==B) Reconstruction();
}
inline int Latest_Modification(int l,int x)
{
for (int i=csize;i>=1;--i) if (con[cache[i][1]].test(x-l+1)) return cache[i][0];
return asstag[x];
}
inline void Reconstruction()
{
for (int j=csize,x,tag;j>=1;--j)
{
if (asstag[x=cache[j][1]]>(tag=cache[j][0])) continue;
for (asstag[x]=tag,que.push(x);!que.empty();)
{
x=que.front(),que.pop();
for (int i=last[x],y;i;i=nxt[i])
if (asstag[y=tov[i]]<cache[j][0]) asstag[y]=tag,que.push(y);
}
}
csize=0;
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 11900kb
input:
4 4 7 1 2 1 3 3 4 2 4 1 1 5 1 2 1 3 3 3 4 2 1 3 3 2 3 3
output:
5 1 1 3
result:
ok 4 number(s): "5 1 1 3"
Test #2:
score: 0
Accepted
time: 4ms
memory: 30300kb
input:
3343 4424 4034 173 57 1235 2820 732 2986 2899 1329 1860 1897 1834 309 1707 1178 2305 488 3294 1074 134 133 2611 607 2704 2665 836 2699 713 492 1652 2548 89 99 420 3322 2323 2451 748 1898 1109 1005 1533 132 1990 2052 523 3251 2510 2499 1345 1667 3038 1649 2916 1896 1362 3144 2075 3307 2564 2488 84 41...
output:
0 0 0 300838484 870463216 870463216 870463216 485088587 193456423 3615600 504286750 504286750 0 507392770 507392770 504286750 536004204 931791220 504286750 507034812 827616625 282262720 0 26277545 26277545 504286750 0 26277545 504286750 26277545 26277545 26277545 447411400 447411400 26277545 2627754...
result:
ok 1376 numbers
Test #3:
score: 0
Accepted
time: 636ms
memory: 218812kb
input:
85950 89112 80029 73024 77362 8532 53238 69145 79470 36758 63248 20873 34334 68005 67010 64196 72442 59071 75793 13581 74325 16575 37604 66202 77925 62022 60029 29673 84624 42140 13625 24956 45522 72206 28442 60158 70734 43117 41379 10673 48671 48651 6547 2061 82339 29091 50707 42304 82880 36824 349...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 39815 numbers
Test #4:
score: 0
Accepted
time: 113ms
memory: 74056kb
input:
43103 44210 44542 40248 28027 11044 38644 27547 13374 9776 21344 11701 38851 10178 40977 10218 41615 6713 10925 20318 30157 17635 13174 12915 41059 39580 19290 39648 16551 5286 28664 21607 22911 32493 22901 31809 1271 8826 33714 9290 40916 34860 10787 28719 1385 12218 11808 35084 17119 21566 39733 3...
output:
104136190 355238100 355238100 355238100 355238100 815103720 815103720 815103720 815103720 815103720 815103720 815103720 815103720 79986600 79986600 815103720 394162008 394162008 398605664 398605664 398605664 815103720 398605664 355238100 182362509 182362509 57336300 355238100 57336300 546928455 5733...
result:
ok 22199 numbers
Test #5:
score: 0
Accepted
time: 514ms
memory: 114140kb
input:
71185 92523 82996 20831 46240 59690 9160 14514 20348 28162 59068 37834 61490 8058 48430 66343 52143 46523 13684 41223 20308 3359 29433 62006 64024 44284 52651 20859 56469 22018 24731 18171 28181 47676 60480 12862 29270 9570 2455 22754 49373 25320 48462 61816 31064 2642 38154 60998 2020 23496 46587 6...
output:
0 660468456 885534492 65612018 885534492 739892120 364794112 364794112 85060824 85060824 364794112 0 861873040 398234275 589879896 589879896 772622930 772622930 772622930 772622930 0 784111616 978832950 784111616 784111616 978832950 420158364 420158364 0 759674968 759674968 818785196 759674968 82838...
result:
ok 41480 numbers
Test #6:
score: 0
Accepted
time: 428ms
memory: 99060kb
input:
60290 89050 85229 54218 10303 14402 4610 19879 19453 2678 22159 6276 39925 3062 9171 48672 43260 25575 18004 18408 11617 33024 20078 55362 24861 52042 21263 13360 11549 16124 56342 24333 25151 54699 52159 2114 17342 53353 22351 39939 58500 29557 57841 16932 30010 1760 48602 5252 17146 39532 9976 828...
output:
0 0 0 0 0 0 0 0 0 741855802 0 741855802 741855802 741855802 0 0 125400876 125400876 0 741855802 0 907267424 907267424 907267424 907267424 568449230 568449230 568449230 568449230 696806828 696806828 0 117784488 117784488 860851200 117784488 310018552 117784488 117784488 0 777779620 310018552 96748990...
result:
ok 42695 numbers
Test #7:
score: 0
Accepted
time: 117ms
memory: 109124kb
input:
34553 40243 42270 15530 13872 12967 6070 19728 8570 230 1958 2414 32509 17244 18815 23272 261 16371 33352 17886 22437 3976 30052 1695 17613 28745 10976 12312 24437 7075 11159 202 11389 32426 13560 20639 2823 27605 9144 19543 23850 1544 29587 32796 13887 22193 21746 4788 2968 21021 14812 25826 11271 ...
output:
0 144307918 516445940 140116918 474073831 218386292 218386292 474073831 675692930 515351594 515351594 474073831 737526710 737526710 737526710 239910324 83292468 474073831 171679382 66463448 875132920 0 527949472 527949472 32854872 32854872 527949472 32854872 59945310 59945310 59945310 59945310 27206...
result:
ok 13922 numbers
Test #8:
score: 0
Accepted
time: 159ms
memory: 106592kb
input:
30567 48344 48210 27187 11280 27470 29690 6893 29109 1927 14985 4179 6164 3071 25048 10722 24629 14405 22972 21102 19864 8965 20145 5122 7199 606 28140 10141 29677 10766 8396 2817 20686 3019 25598 15908 14924 27949 20432 685 21392 12805 24998 13598 10702 26163 19388 28296 1099 9356 7934 11495 20576 ...
output:
992031430 0 0 223648936 0 666841846 666841846 666841846 978426852 978426852 267035080 596837372 596837372 19672689 179713056 179713056 179713056 270867760 179713056 179713056 179713056 270867760 152879976 152879976 998870870 179713056 36688616 676629325 804513163 676629325 676629325 676629325 676629...
result:
ok 16081 numbers
Test #9:
score: 0
Accepted
time: 474ms
memory: 149644kb
input:
67000 100000 100000 10959 52809 35920 41389 38383 65717 21953 41629 6471 11757 6359 9978 23387 45190 30615 18037 49495 66203 29889 47106 64438 37246 6325 41642 28611 23131 15477 43145 38082 23483 35163 6784 22018 52317 4103 35110 47713 48433 5907 56973 54679 51040 42100 39131 48180 13405 57449 2995 ...
output:
1000000000 999827654 999827654 999827654 999827654 1000000000 999827654 999827654 1000000000 999827654 999827654 1000000000 999827654 999827654 999827654 999827654 999827654 999827654 999827654 999827654 999827654 999827654 999827654 999827654 999827654 999827654 999827654 1000000000 1000000000 9998...
result:
ok 79999 numbers
Test #10:
score: 0
Accepted
time: 674ms
memory: 196972kb
input:
67000 100000 100000 18932 19062 65983 52063 44247 8974 14409 49196 15143 11826 7386 29116 54625 14972 40870 59243 35444 35753 30926 59139 62325 7111 34439 48944 66315 59368 14842 63142 36652 58628 42716 50503 1040 26202 31022 19955 60682 38483 1921 51279 63418 24845 41974 23348 21567 37276 11041 498...
output:
1000000000 999638796 1000000000 1000000000 998734558 1000000000 1000000000 998734558 998734558 999217018 998700374 998700374 998955400 1000000000 997819345 998273079 997580912 997580912 997653478 998700374 997580912 997653478 996545486 996545486 1000000000 997653478 997653478 998955400 997653478 997...
result:
ok 39999 numbers
Test #11:
score: 0
Accepted
time: 579ms
memory: 219972kb
input:
99900 100000 100000 44158 25720 25720 84658 84658 90057 90057 99607 99607 50202 50202 18449 18449 66784 66784 27116 27116 32648 32648 49102 49102 49766 49766 362 362 83161 83161 26936 26936 69299 69299 89390 89390 53329 53329 19924 19924 16383 16383 73600 73600 7389 7389 23696 23696 2319 2319 49849 ...
output:
0 251700135 93413907 0 227994864 390102066 390102066 189580498 348085003 348085003 403664388 293544632 333683571 335261671 997946526 463876419 463876419 270069877 963267420 347401558 87471256 970980492 152537177 32854536 32854536 32854536 32854536 32854536 786327655 127303123 62179846 62179846 97737...
result:
ok 25197 numbers
Test #12:
score: 0
Accepted
time: 799ms
memory: 220168kb
input:
100000 100000 100000 44158 25720 25720 84658 84658 90057 90057 99607 99607 50202 50202 18449 18449 66784 66784 27116 27116 32648 32648 49102 49102 49766 49766 362 362 83161 83161 26936 26936 69299 69299 89390 89390 53329 53329 19924 19924 16383 16383 73600 73600 7389 7389 23696 23696 2319 2319 49849...
output:
0 769123697 906050317 906050317 906050317 245749425 0 245749425 188039952 662481632 835310528 899943844 899943844 933792298 899943844 33997882 932454470 97034149 247365105 714041190 247365105 247365105 753591274 644990562 247365105 120122644 120122644 535863644 495501255 522775472 522775472 67986686...
result:
ok 24894 numbers
Test #13:
score: 0
Accepted
time: 5ms
memory: 32472kb
input:
3255 4696 4719 1589 2677 2570 2294 2150 2071 1868 2920 1269 1606 2588 1041 3193 589 1546 2107 2207 3062 11 2908 3011 1396 2947 1523 1990 777 1294 973 1741 605 774 3121 979 666 2181 2949 161 2291 584 1829 809 1169 3171 2947 595 867 1030 621 1467 539 2267 3168 2343 1142 2602 1045 1669 1918 2555 993 20...
output:
740984992 45281375 0 0 238528619 269024544 0 228154903 601220387 111049560 149102290 0 717799440 684475696 120663494 475352426 684475696 125692433 125692433 379436594 379436594 379436594 379436594 66496040 149102290 66496040 634035550 684475696 662773031 606172244 300050753 360151980 415625051 36015...
result:
ok 1583 numbers