QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#244609 | #7764. 世界沉睡童话 | zhoukangyang# | 1.5 | 4841ms | 102500kb | C++11 | 3.2kb | 2023-11-09 13:27:39 | 2024-07-04 02:23:50 |
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;
int mx_sub[N], mn_sub[N];
void dfs(int x) {
s[++stop] = x;
mx_sub[x] = a[x], mn_sub[x] = a[x];
for(auto&v : son[x]) {
fa[v] = x;
dfs(v);
mx_sub[x] = max(mx_sub[x], mx_sub[v]);
mn_sub[x] = min(mn_sub[x], mn_sub[v]);
}
}
void dfs1(int 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) {
if(lim <= s[rt]) {
if(mx_sub[rt] < aimp) {
(ans += pw[rec - top]) %= mod;
return;
}
if(mn_sub[rt] > aimp) {
return ;
}
}
// 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(((double) clock() - st) / CLOCKS_PER_SEC > 4.8) {
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: 0.5
Acceptable Answer
Test #1:
score: 0.5
Acceptable Answer
time: 4ms
memory: 74292kb
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 443217
result:
points 0.10 Your answer to Question 1 is correct. 10%.
Test #2:
score: 5
Accepted
time: 8ms
memory: 74284kb
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: 0.5
Acceptable Answer
time: 7ms
memory: 73568kb
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 524288
result:
points 0.10 Your answer to Question 1 is correct. 10%.
Subtask #2:
score: 0.5
Acceptable Answer
Test #4:
score: 0.5
Acceptable Answer
time: 28ms
memory: 79872kb
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 685772584
result:
points 0.10 Your answer to Question 1 is correct. 10%.
Test #5:
score: 0.5
Acceptable Answer
time: 24ms
memory: 78956kb
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 228211102
result:
points 0.10 Your answer to Question 1 is correct. 10%.
Test #6:
score: 0.5
Acceptable Answer
time: 23ms
memory: 79212kb
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 141570868
result:
points 0.10 Your answer to Question 1 is correct. 10%.
Subtask #3:
score: 0.5
Acceptable Answer
Dependency #2:
10%
Acceptable Answer
Test #7:
score: 0.5
Acceptable Answer
time: 38ms
memory: 102500kb
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 923978195
result:
points 0.10 Your answer to Question 1 is correct. 10%.
Test #8:
score: 0.5
Acceptable Answer
time: 41ms
memory: 79824kb
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 532845632
result:
points 0.10 Your answer to Question 1 is correct. 10%.
Test #9:
score: 0.5
Acceptable Answer
time: 27ms
memory: 78536kb
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 399460726
result:
points 0.10 Your answer to Question 1 is correct. 10%.
Subtask #4:
score: 0
Wrong Answer
Dependency #2:
10%
Acceptable Answer
Test #10:
score: 5
Accepted
time: 30ms
memory: 81320kb
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.5
Acceptable Answer
time: 4805ms
memory: 81736kb
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:
YES no comment no comment
result:
points 0.10 Your answer to Question 1 is correct. 10%.
Test #12:
score: 0
Wrong Answer
time: 4841ms
memory: 80580kb
input:
80000 1 51403 43298 36255 30628 71642 1172 72452 42485 56088 13897 14689 1329 30730 20044 69736 78928 36520 29140 66633 53336 9061 64982 16774 8311 18347 41865 66679 25376 15633 7047 9244 38840 29360 34593 35221 29546 66474 62134 53176 72767 36402 11944 46808 71900 13231 23302 71179 54895 74879 6071...
output:
result:
wrong output format Output file not found: ""
Subtask #5:
score: 0
Skipped
Dependency #3:
10%
Acceptable Answer
Dependency #4:
0%
Subtask #6:
score: 0
Skipped
Dependency #4:
0%
Subtask #7:
score: 0
Skipped
Dependency #1:
10%
Acceptable Answer
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%