QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#233909 | #7439. 铃原露露 | HaccerKat | 25 | 127ms | 3512kb | C++20 | 6.0kb | 2023-11-01 08:09:55 | 2023-11-01 08:09:55 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
template<typename T>
int SIZE(T (&t)){
return t.size();
}
template<typename T, size_t N>
int SIZE(T (&t)[N]){
return N;
}
string to_string(char t){
return "'" + string({t}) + "'";
}
string to_string(bool t){
return t ? "true" : "false";
}
string to_string(const string &t, int x1=0, int x2=1e9){
string ret = "";
for(int i = min(x1,SIZE(t)), _i = min(x2,SIZE(t)-1); i <= _i; ++i){
ret += t[i];
}
return '"' + ret + '"';
}
string to_string(const char* t){
string ret(t);
return to_string(ret);
}
template<size_t N>
string to_string(const bitset<N> &t, int x1=0, int x2=1e9){
string ret = "";
for(int i = min(x1,SIZE(t)); i <= min(x2,SIZE(t)-1); ++i){
ret += t[i] + '0';
}
return to_string(ret);
}
template<typename T, typename... Coords>
string to_string(const T (&t), int x1=0, int x2=1e9, Coords... C);
template<typename T, typename S>
string to_string(const pair<T, S> &t){
return "(" + to_string(t.first) + ", " + to_string(t.second) + ")";
}
template<typename T, typename... Coords>
string to_string(const T (&t), int x1, int x2, Coords... C){
string ret = "[";
x1 = min(x1, SIZE(t));
auto e = begin(t);
advance(e,x1);
for(int i = x1, _i = min(x2,SIZE(t)-1); i <= _i; ++i){
ret += to_string(*e, C...) + (i != _i ? ", " : "");
e = next(e);
}
return ret + "]";
}
template<int Index, typename... Ts>
struct print_tuple{
string operator() (const tuple<Ts...>& t) {
string ret = print_tuple<Index - 1, Ts...>{}(t);
ret += (Index ? ", " : "");
return ret + to_string(get<Index>(t));
}
};
template<typename... Ts>
struct print_tuple<0, Ts...> {
string operator() (const tuple<Ts...>& t) {
return to_string(get<0>(t));
}
};
template<typename... Ts>
string to_string(const tuple<Ts...>& t) {
const auto Size = tuple_size<tuple<Ts...>>::value;
return print_tuple<Size - 1, Ts...>{}(t);
}
void dbgr(){;}
template<typename Heads, typename... Tails>
void dbgr(Heads H, Tails... T){
cout << to_string(H) << " | ";
dbgr(T...);
}
void dbgs(){;}
template<typename Heads, typename... Tails>
void dbgs(Heads H, Tails... T){
cout << H << " ";
dbgs(T...);
}
/*
formatted functions:
*/
/*
consider __VA_ARGS__ as a whole:
dbgv() prints values only
dbg() prints name and values
*/
#define dbgv(...) cout << to_string(__VA_ARGS__) << endl;
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgv(__VA_ARGS__);
//#define dbg(...)
/*
consider __VA_ARGS__ as a sequence of arguments:
dbgr() prints values only
dbgm() prints names and values
*/
#define dbgr(...) dbgr(__VA_ARGS__); cout << endl;
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgr(__VA_ARGS__);
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
// http://xorshift.di.unimi.it/splitmix64.c
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
// using u128 = __uint128_t;
// using i128 = __int128;
const int mod = 1000000007;
const int N = 105;
const int LOG = 20;
const int inf = 1e9;
const double eps = 1e-11;
int n, m, k, qq;
int a[N], f[N], p[N];
vector<int> adj[N];
int dep[N], tin[N], logA[N * 2];
int rmq[N * 2][LOG];
bool vis[N];
vector<int> euler;
int timer = 0;
void dfs(int u) {
vis[u] = true, tin[u] = timer++;
euler.push_back(u);
for (int v : adj[u]) {
if (!vis[v]) {
dep[v] = dep[u] + 1;
dfs(v);
euler.push_back(u);
timer++;
}
}
}
void precomp() {
int sz = euler.size();
for (int i = 2; i <= sz; i++) logA[i] = logA[i >> 1] + 1;
for (int i = 0; i < sz; i++) {
rmq[i][0] = euler[i];
}
for (int j = 1; j < LOG; j++) {
for (int i = 0; i + (1 << j) <= sz; i++) {
int x = (1 << j - 1);
int lx = dep[rmq[i][j - 1]], rx = dep[rmq[i + x][j - 1]];
rmq[i][j] = (lx < rx ? rmq[i][j - 1] : rmq[i + x][j - 1]);
}
}
}
int getlca(int u, int v) {
int l = tin[u], r = tin[v];
if (l > r) swap(l, r);
int len = r - l + 1;
int lg = logA[len], x = 1 << lg;
int lx = dep[rmq[l][lg]], rx = dep[rmq[r - x + 1][lg]];
return (lx < rx ? rmq[l][lg] : rmq[r - x + 1][lg]);
}
int getdist(int u, int v) {
return dep[u] + dep[v] - 2 * dep[getlca(u, v)];
}
bool ok[N][N];
void solve() {
cin >> n >> qq;
for (int i = 0; i < n; i++) {
cin >> a[i];
a[i]--;
p[a[i]] = i;
}
for (int i = 1; i < n; i++) {
cin >> f[i];
f[i]--;
adj[f[i]].push_back(i);
}
dfs(0);
precomp();
while (qq--) {
int l, r;
cin >> l >> r;
l--, r--;
memset(ok, 0, sizeof(ok));
for (int i = l; i <= r; i++) {
for (int j = i; j <= r; j++) {
for (int k = i; k <= j; k++) {
for (int x = k; x <= j; x++) {
int lca = getlca(p[k], p[x]);
ok[i][j] |= (a[lca] < i || a[lca] > j);
}
}
}
}
ll out = 0;
for (int i = l; i <= r; i++) {
for (int j = i; j <= r; j++) {
out += !ok[i][j];
}
}
cout << out << "\n";
}
}
int32_t main() {
std::ios::sync_with_stdio(false);
cin.tie(NULL);
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 25
Accepted
Test #1:
score: 25
Accepted
time: 120ms
memory: 3492kb
input:
100 100 5 29 12 16 25 36 18 37 27 47 34 40 20 3 1 42 26 19 33 41 6 22 8 58 32 62 24 15 35 17 59 30 50 61 43 49 39 67 44 21 13 31 68 69 65 64 10 28 38 54 70 63 9 46 66 52 23 7 48 60 55 56 51 2 57 11 53 14 45 4 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:
9 87 37 4 13 13 48 17 175 32 46 29 66 40 23 28 43 113 34 37 38 39 85 28 8 64 37 67 1 42 104 7 43 38 4 53 8 14 86 16 61 36 78 7 45 74 84 17 4 51 74 312 80 26 6 56 27 4 83 11 20 39 8 194 78 67 75 66 51 16 2 14 6 47 80 47 11 91 62 59 99 81 92 9 1 43 92 7 22 55 86 56 32 17 27 83 70 10 24 26
result:
ok 100 numbers
Test #2:
score: 0
Accepted
time: 93ms
memory: 3408kb
input:
100 100 1 2 3 4 5 6 7 8 9 10 14 11 17 13 12 15 16 18 19 20 25 22 27 26 23 21 24 28 29 30 31 35 32 34 33 41 36 37 39 40 38 47 45 42 44 49 43 48 46 50 53 54 52 51 55 56 57 58 61 59 63 62 60 65 68 64 67 66 69 70 71 72 73 74 75 76 77 78 81 84 82 79 83 80 85 86 87 92 91 90 89 88 93 94 95 96 97 98 99 100 ...
output:
200 52 97 176 147 86 184 184 14 105 177 208 39 36 198 2 19 103 78 174 173 13 27 27 180 152 193 21 45 20 20 169 68 103 17 18 129 20 11 41 152 54 26 189 32 179 158 95 16 3 214 140 172 11 177 3 6 184 2 1 171 5 110 8 6 40 10 11 29 118 198 127 9 17 134 184 177 10 1 8 25 131 24 13 175 11 9 196 191 4 137 1...
result:
ok 100 numbers
Test #3:
score: 0
Accepted
time: 66ms
memory: 3440kb
input:
98 98 1 3 2 5 4 6 7 8 9 10 11 12 13 14 15 16 17 19 18 20 21 23 22 25 24 26 28 27 29 30 31 32 33 34 35 36 37 38 39 40 41 43 42 44 45 47 46 49 48 51 50 52 53 55 54 56 57 58 59 60 61 62 63 64 65 67 66 68 69 70 71 72 73 74 75 76 79 77 78 80 81 83 82 84 85 87 86 88 90 89 91 92 93 94 96 95 97 98 1 2 3 4 1...
output:
36 327 67 48 325 176 206 288 10 102 773 157 10 239 93 396 383 511 596 289 28 236 66 99 460 244 228 332 81 187 409 254 6 3 105 23 15 242 184 76 310 21 268 295 15 55 303 212 240 214 184 322 24 160 197 192 106 1 11 487 458 105 32 156 84 312 2 480 223 92 112 36 327 304 99 55 66 273 321 159 29 615 292 28...
result:
ok 98 numbers
Test #4:
score: 0
Accepted
time: 127ms
memory: 3444kb
input:
100 99 1 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 77 37 67 49 60 69 71 62 82 84 63 75 50 66 56 57 44 40 36 42 85 81 46 76 83 45 79 47 68 52 80 72 43 74 48 34 65 61 38 51 59 53 78 55 41 73 39 58 54 64 70 35 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 1...
output:
85 58 14 8 40 29 93 50 74 35 40 73 178 2 11 1 104 35 34 7 27 8 14 7 8 11 61 40 53 71 14 42 57 46 88 51 27 57 49 37 2 28 55 43 96 97 4 20 52 83 59 31 38 18 24 24 8 2 31 57 13 1 22 31 39 61 105 31 57 27 15 39 4 34 3 39 45 25 69 33 5 81 1 7 48 34 26 74 58 5 27 6 6 13 66 41 86 32 13
result:
ok 99 numbers
Test #5:
score: 0
Accepted
time: 101ms
memory: 3492kb
input:
100 100 1 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:
9 55 375 78 211 144 173 513 116 3 21 166 154 1 204 709 470 202 66 270 78 139 529 61 666 71 91 67 10 10 412 25 375 185 109 420 100 158 6 46 567 57 15 183 211 91 323 45 195 280 649 329 78 615 78 55 150 3 130 86 534 388 345 646 443 32 140 457 561 667 36 276 3 146 28 67 489 301 678 1 392 274 141 36 739 ...
result:
ok 100 numbers
Test #6:
score: 0
Accepted
time: 78ms
memory: 3456kb
input:
100 100 1 2 3 17 76 53 67 31 84 35 58 61 50 85 5 56 49 66 6 38 42 39 51 63 48 57 59 78 45 18 23 25 44 72 36 26 54 86 19 79 80 87 90 40 46 22 33 82 14 70 27 92 20 28 41 74 7 60 100 93 12 55 32 98 43 62 97 81 88 34 29 95 37 16 30 21 71 52 8 47 24 89 91 15 99 64 4 69 68 65 9 94 83 11 96 77 75 13 10 73 ...
output:
113 131 213 176 5 16 66 54 3 59 2 78 29 13 28 35 5 86 10 218 185 32 34 111 218 55 147 88 16 44 25 76 104 17 111 17 92 1 79 68 11 27 207 26 88 58 42 23 126 80 31 68 169 2 28 30 3 81 187 40 33 152 178 24 22 63 204 56 22 77 64 68 139 1 121 29 12 143 5 94 196 71 155 149 118 2 71 80 117 183 137 3 99 114 ...
result:
ok 100 numbers
Test #7:
score: 0
Accepted
time: 75ms
memory: 3424kb
input:
100 100 1 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 53 67 46 58 47 34 49 75 51 32 40 56 36 44 35 38 37 48 33 61 64 52 43 39 62 45 65 72 73 76 60 42 78 54 66 77 68 70 63 71 41 50 55 69 57 74 59 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 ...
output:
17 36 7 114 153 96 91 13 11 153 70 114 57 10 22 89 1 32 138 21 22 56 121 23 118 5 42 34 32 2 141 45 8 150 149 159 105 159 83 1 11 22 141 117 170 33 14 142 131 142 164 114 143 62 91 161 44 96 60 38 55 38 99 141 32 107 122 164 49 161 138 18 88 6 3 34 182 32 125 195 73 149 65 21 170 122 189 6 62 14 83 ...
result:
ok 100 numbers
Test #8:
score: 0
Accepted
time: 60ms
memory: 3464kb
input:
100 98 55 2 3 4 100 5 6 7 8 9 10 11 12 24 14 15 16 30 17 18 19 20 21 22 72 13 25 26 27 28 29 31 32 33 34 35 36 37 38 39 40 91 41 42 43 84 45 46 47 48 49 50 51 52 53 54 1 56 57 58 59 60 61 62 90 63 64 65 66 67 68 69 70 71 23 73 74 75 76 77 78 79 80 81 82 83 44 85 86 87 88 89 92 93 94 99 95 96 97 98 1...
output:
18 478 190 36 21 28 201 98 2246 1286 527 171 78 617 435 36 339 200 827 465 351 230 21 231 10 6 219 78 1048 253 190 237 1854 2144 66 6 67 359 107 2699 1 668 106 253 239 28 1018 55 136 2713 2140 556 15 91 313 36 572 228 36 66 2384 542 10 229 70 45 378 45 120 91 231 3 344 429 78 1636 459 36 205 476 257...
result:
ok 98 numbers
Test #9:
score: 0
Accepted
time: 78ms
memory: 3496kb
input:
100 100 65 23 4 24 2 83 9 69 25 52 86 29 50 5 68 66 54 30 57 31 35 26 75 74 6 79 37 8 11 58 80 12 60 87 59 91 85 89 7 13 56 18 3 17 61 43 62 63 94 46 92 67 20 21 99 88 15 93 64 34 70 40 14 19 10 27 100 51 78 55 82 36 77 32 39 90 16 96 48 22 1 71 33 47 49 53 84 76 95 38 41 81 44 97 45 28 72 42 73 98 ...
output:
15 5 4 252 70 144 39 43 13 44 488 25 339 61 32 60 200 103 294 226 38 38 4 68 143 30 305 19 14 41 14 49 63 94 60 55 356 22 40 336 211 52 108 58 294 63 12 338 62 74 318 18 13 95 70 371 2 19 66 37 102 78 331 161 83 29 55 23 397 24 43 72 63 97 26 86 50 18 21 33 132 352 81 38 49 53 36 201 17 105 209 91 4...
result:
ok 100 numbers
Test #10:
score: 0
Accepted
time: 106ms
memory: 3512kb
input:
100 99 3 2 4 5 67 14 32 22 77 83 16 27 15 39 20 42 57 31 82 68 17 80 40 65 84 43 52 18 85 33 70 86 63 72 58 24 25 44 10 8 21 100 28 93 73 23 1 98 19 29 91 41 66 30 13 95 36 53 60 74 7 64 99 49 97 45 47 35 11 46 87 26 48 71 81 59 79 88 76 61 34 12 75 90 55 94 6 37 62 9 50 38 92 51 96 78 89 54 69 56 1...
output:
27 94 143 50 15 52 192 85 88 142 30 84 92 28 169 139 80 6 101 32 41 148 26 36 89 18 62 1 290 94 118 46 172 119 87 156 58 170 15 81 113 40 35 186 60 181 114 29 116 31 73 83 171 53 138 65 205 283 125 185 52 217 31 63 9 28 3 99 87 62 204 9 112 49 103 18 61 217 93 189 48 144 80 45 166 152 88 8 36 20 61 ...
result:
ok 99 numbers
Subtask #2:
score: 0
Runtime Error
Dependency #1:
100%
Accepted
Test #11:
score: 0
Runtime Error
input:
3000 3000 15 2125 1789 1745 2433 755 747 1188 116 2493 2185 789 1878 1756 2326 500 1213 1733 1064 217 1790 48 779 35 1119 2235 2553 1421 916 1974 438 1579 1847 423 1011 2969 541 1155 1045 1021 2748 2670 868 229 929 2896 1339 2456 1985 2798 2008 144 2648 1120 41 1362 453 353 467 581 1594 2804 2252 19...
output:
result:
Subtask #3:
score: 0
Runtime Error
Test #21:
score: 0
Runtime Error
input:
200000 1 73119 155820 110077 139724 136809 18709 57745 43535 89117 43647 20295 60551 108184 188031 180437 52363 72969 130559 179796 75852 53879 96998 63387 76458 193661 142318 28260 40465 80050 188507 143795 141018 94880 71333 7644 109237 105208 109509 9779 159914 135096 47638 175577 182927 173100 1...
output:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
0%