QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#244599 | #7764. 世界沉睡童话 | zhoukangyang# | 15 | 59ms | 94140kb | C++11 | 2.8kb | 2023-11-09 13:11:12 | 2024-07-04 02:23:46 |
Judging History
answer
#include<bits/stdc++.h>
#define L(i, j, k) for(int i = (j); i <= (k); ++i)
#define R(i, j, k) for(int i = (j); i >= (k); --i)
#define ll long long
#define vi vector <int>
#define sz(a) ((int) (a).size())
#define me(f, x) memset(f, x, sizeof(f))
#define uint unsigned int
#define ull unsigned long long
#define i128 __int128
using namespace std;
const int N = 1 << 20, Mod = 1019260817, G = 19491001;
const int mod = 998244353;
int n, rt;
vi son[N];
int s[N], fa[N], top;
int a[N], p[N];
int stop;
void dfs(int x) {
s[++stop] = x;
for(auto&v : son[x]) {
fa[v] = x;
dfs(v);
}
}
int Pw[N], SUM[N];
void chck_slv(int x) {
SUM[x] = (Pw[a[x]] + Mod - Pw[p[x]]) % Mod;
for(auto&v : son[x]) {
chck_slv(v);
(SUM[x] += SUM[v]) %= Mod;
}
}
bool chck() {
vi np(n + 1);
L(i, 1, n)
np[i] = a[i];
chck_slv(rt);
L(i, 2, n) {
if(SUM[s[i]]) {
swap(np[s[i]], np[fa[s[i]]]);
}
}
L(i, 1, n)
if(np[i] != p[i])
return 0;
return 1;
}
int mp[N];
vector < pair < int, int > > vp[N];
int vis[N];
pair < int, int > stk[N];
vector < pair < int, int > > vec;
int fnd = 0, ans;
int aimp, rec, pw[N];
void Get(int rt, int lim) {
// cout << " rt = " << rt << ' ' << rec << endl;
auto K = lower_bound(vp[rt].begin(), vp[rt].end(), make_pair(lim, -114514));
if(K == vp[rt].begin()) {
if(a[rt] == aimp) {
fnd = 1, vec.clear();
L(i, 1, top)
vec.emplace_back(stk[i]);
} else if(a[rt] < aimp) {
(ans += pw[rec - top]) %= mod;
}
return ;
}
--K;
int v = K -> second;
int e = K -> first;
L(c, 0, 1) {
if(vis[e] != -1 && vis[e] != c)
continue;
int pb = 0;
if(vis[e] == -1)
pb = 1, stk[++top] = {e, c};
if(c) Get(v, e);
else Get(rt, e);
if(pb) --top;
}
}
int main () {
ios :: sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> rt;
L(i, 1, n) {
cin >> a[i];
}
L(i, 1, n) {
int k;
cin >> k;
while(k--) {
int x;
cin >> x;
son[i].emplace_back(x);
}
}
dfs(rt);
L(i, 1, n) {
cin >> p[i];
}
Pw[0] = 1;
L(i, 1, n) {
Pw[i] = (ll) Pw[i - 1] * G % Mod;
}
L(i, 2, n) {
int u = s[i];
vp[fa[u]].emplace_back(i, u);
vp[u].emplace_back(i, fa[u]);
}
if(chck()) cout << "YES\n";
else cout << "NO\n";
cout << "no comment\n";
L(i, 1, n) {
mp[p[i]] = i;
}
L(i, 2, n) {
vis[i] = -1;
}
pw[0] = 1;
L(i, 1, n)
pw[i] = (ll) pw[i - 1] * 2 % mod;
auto st = clock();
rec = n - 1;
ans = 0;
L(rt, 1, n) {
aimp = p[rt], vec.clear(), fnd = 0;
top = 0;
Get(rt, n + 1);
if(!fnd) {
break;
}
for(auto&r : vec)
vis[r.first] = r.second;
rec -= sz(vec);
if((st - clock()) / CLOCKS_PER_SEC > 4.9) {
cout << "no comment\n";
return 0;
}
}
cout << ans << '\n';
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 8ms
memory: 69548kb
input:
20 10 20 6 18 12 8 14 15 5 1 17 11 10 19 13 7 16 2 9 3 4 3 13 16 20 1 4 1 17 0 1 19 0 0 0 3 5 8 11 3 1 3 18 0 0 2 15 12 3 6 9 2 1 14 0 0 0 1 7 0 19 6 17 12 3 14 13 5 8 9 11 7 10 1 20 16 2 18 15 4
output:
YES no comment 443216
result:
ok Your answer to Question 3 is correct. 100%.
Test #2:
score: 5
Accepted
time: 0ms
memory: 69808kb
input:
20 15 10 16 5 1 14 15 2 8 19 9 6 3 7 12 13 11 4 20 17 18 0 0 1 10 0 0 1 17 0 3 6 20 19 3 8 12 1 1 5 3 18 14 2 2 11 13 0 0 2 9 16 1 3 1 7 1 4 0 0 12 18 9 7 5 16 20 3 17 2 14 15 13 19 11 6 1 10 8 4
output:
NO no comment 458752
result:
ok Your answer to Question 3 is correct. 100%.
Test #3:
score: 5
Accepted
time: 3ms
memory: 70860kb
input:
20 20 7 6 19 4 16 12 1 15 14 10 8 13 9 18 3 17 2 11 5 20 3 4 14 10 0 3 9 2 16 0 1 18 0 0 2 17 5 0 2 6 12 0 1 3 2 11 1 1 8 0 0 0 1 19 1 15 2 13 7 20 19 17 4 18 12 9 16 14 13 8 10 7 15 11 6 2 5 3 1
output:
YES no comment 524287
result:
ok Your answer to Question 3 is correct. 100%.
Subtask #2:
score: 5
Accepted
Test #4:
score: 5
Accepted
time: 35ms
memory: 75468kb
input:
80000 1 77649 27240 19178 10270 1981 6216 42189 63630 66779 68852 46110 27187 4598 75779 69930 43632 68065 13395 33234 17719 76420 65825 3003 67410 18637 3380 32923 66692 9430 1915 118 62287 69323 9735 72936 30221 46487 33367 59048 61582 55572 10657 61645 68649 23643 39197 38086 66512 58864 51881 69...
output:
YES no comment 524240706
result:
ok Your answer to Question 3 is correct. 100%.
Test #5:
score: 5
Accepted
time: 36ms
memory: 75640kb
input:
80000 1 40751 74046 38639 8349 10511 79922 55598 63363 5123 68628 47324 17756 21270 35623 48141 31851 51342 75440 32 64257 20805 21871 72745 39461 76181 72542 12937 23663 69050 49377 74431 74875 66326 28811 65655 37532 53189 6723 56502 67191 76122 35519 22721 36131 31071 4212 11534 64384 71045 33940...
output:
NO no comment 10861120
result:
ok Your answer to Question 3 is correct. 100%.
Test #6:
score: 5
Accepted
time: 27ms
memory: 94140kb
input:
80000 1 52 92 20 169 34 249 69 125 25 131 77 32 55 182 43 150 219 5 15 236 26 155 6 19 39 4 93 23 21 47 318 40 179 328 7 38 95 42 146 49 268 227 61 214 36 148 73 3 10 60 90 33 28 56 220 18 122 46 64 188 44 1 50 396 173 218 561 58 51 79 72 53 17 100 97 66 78 118 8 68 80 81 211 84 99 136 133 205 11 11...
output:
NO no comment 599441604
result:
ok Your answer to Question 3 is correct. 100%.
Subtask #3:
score: 5
Accepted
Dependency #2:
100%
Accepted
Test #7:
score: 5
Accepted
time: 52ms
memory: 75500kb
input:
80000 3823 8672 63816 1855 36775 59031 46214 57526 45575 56480 24946 44377 71695 48249 27546 7294 50921 44846 15666 48938 25415 52920 13826 22835 21341 1142 24320 29132 52868 64771 21558 60343 15685 75914 11345 44134 68985 77283 78587 12672 69815 6415 5331 75886 12703 35068 3032 31409 31937 9552 185...
output:
YES no comment 612179383
result:
ok Your answer to Question 3 is correct. 100%.
Test #8:
score: 5
Accepted
time: 59ms
memory: 74708kb
input:
80000 60188 5794 26969 68934 26583 48201 17389 14742 77469 44368 2137 74498 60703 9179 31494 20743 20484 30465 15763 2175 10298 54198 810 52901 22117 69570 14168 20437 66380 11645 68961 53532 24346 8175 66161 79610 68212 11083 30646 53788 257 6139 33662 24868 65419 14595 38655 32846 48437 5746 7958 ...
output:
NO no comment 196571817
result:
ok Your answer to Question 3 is correct. 100%.
Test #9:
score: 5
Accepted
time: 51ms
memory: 75448kb
input:
80000 79998 1148 7193 27496 1966 51563 50524 12463 55117 63933 49247 60771 74288 46586 10841 55278 15357 76933 58367 3881 42134 41227 41943 36434 22191 61595 51327 67615 76770 25655 17597 49007 19958 22646 43900 8657 46333 46826 45346 39216 23828 50433 15579 72477 4164 43118 71917 18319 23835 40211 ...
output:
YES no comment 291865406
result:
ok Your answer to Question 3 is correct. 100%.
Subtask #4:
score: 0
Time Limit Exceeded
Dependency #2:
100%
Accepted
Test #10:
score: 5
Accepted
time: 29ms
memory: 77044kb
input:
80000 1 23182 57274 19130 76507 5924 29197 57478 51488 74017 47401 32091 39255 79861 41955 26974 60662 2225 70963 4735 74401 52909 69178 36760 4690 44532 40697 73039 16264 67322 64193 8773 62412 3428 53091 14416 64609 25648 38035 58938 30410 9510 44821 74764 18342 70921 74358 36541 4577 75727 28512 ...
output:
NO no comment 295664390
result:
ok Your answer to Question 3 is correct. 100%.
Test #11:
score: 0
Time Limit Exceeded
input:
80000 1 61602 27516 53669 51811 14948 76631 192 16777 38570 5946 6954 12227 19942 68561 44448 64006 37108 15992 41511 40400 74124 37704 11985 29943 7097 41084 19256 29568 37388 56685 22863 77327 58896 48299 22126 51515 68870 30219 42431 18685 19954 27935 44008 75233 1372 26374 13728 29643 15853 1632...
output:
result:
Subtask #5:
score: 0
Skipped
Dependency #3:
100%
Accepted
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #5:
0%
Subtask #8:
score: 0
Skipped
Dependency #7:
0%
Subtask #9:
score: 0
Skipped
Dependency #8:
0%
Subtask #10:
score: 0
Skipped
Dependency #9:
0%