#include <bits/stdc++.h>
using namespace std;
// macros
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<ll, ll> lll;
typedef tuple<int, int, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<lll> vlll;
#define REP(a,b,c) for(int a=int(b); a<int(c); a++)
#define RE(a,c) REP(a,0,c)
#define RE1(a,c) REP(a,1,c+1)
#define REI(a,b,c) REP(a,b,c+1)
#define REV(a,b,c) for(int a=int(c-1); a>=int(b); a--)
#define FOR(a,b) for(auto& a : b)
#define all(a) a.begin(), a.end()
#define INF 1e18
#define EPS 1e-9
#define pb push_back
#define popb pop_back
#define fi first
#define se second
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
// input
template<class T> void IN(T& x) {cin >> x;}
template<class H, class... T> void IN(H& h, T&... t) {IN(h); IN(t...); }
// output
template<class T1, class T2> void OUT(const pair<T1,T2>& x);
template<class T> void OUT(const vector<T>& x);
template<class T> void OUT(const T& x) {cout << x;}
template<class H, class... T> void OUT(const H& h, const T&... t) {OUT(h); OUT(t...); }
template<class T1, class T2> void OUT(const pair<T1,T2>& x) {OUT(x.fi,' ',x.se);}
template<class T> void OUT(const vector<T>& x) {RE(i,x.size()) OUT(i==0?"":" ",x[i]);}
template<class... T> void OUTL(const T&... t) {OUT(t..., "\n"); }
template<class H> void OUTLS(const H& h) {OUTL(h); }
template<class H, class... T> void OUTLS(const H& h, const T&... t) {OUT(h,' '); OUTLS(t...); }
// dp
template<class T> bool ckmin(T&a, T&b) { bool bl = a > b; a = min(a,b); return bl;}
template<class T> bool ckmax(T&a, T&b) { bool bl = a < b; a = max(a,b); return bl;}
void program();
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
program();
}
//===================//
// begin program //
//===================//
const int MX = 2e5+10;
const int SQ = 502;
const int N = (1<<20);
int n, r, q;
int h[MX], p[MX];
vi withH[MX];
vi chl[MX];
int ways[MX][SQ];
int tot[MX];
void program() {
// input
IN(n,r,q);
RE1(i,n) {
if(i != 1) {
IN(p[i]);
chl[p[i]].pb(i);
} else p[i] = -1;
IN(h[i]);
withH[h[i]].pb(i);
}
if(r >= SQ) return;
memset(ways,0,sizeof(ways));
RE1(j,r) {
// fill tot
memset(tot,0,sizeof(tot));
FOR(u,withH[j]) tot[u] = 1;
REV(u,1,n+1) FOR(v,chl[u]) tot[u] += tot[v];
RE1(i,n) ways[h[i]][j] += tot[i];
}
// answer queries
RE(_,q) {
int r1, r2; IN(r1,r2);
OUTL(ways[r1][r2]);
cout.flush();
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
76 ms |
131076 KB |
Execution killed with signal 9 |
2 |
Runtime error |
64 ms |
131076 KB |
Execution killed with signal 9 |
3 |
Runtime error |
67 ms |
131076 KB |
Execution killed with signal 9 |
4 |
Runtime error |
61 ms |
131076 KB |
Execution killed with signal 9 |
5 |
Runtime error |
62 ms |
131076 KB |
Execution killed with signal 9 |
6 |
Runtime error |
71 ms |
131076 KB |
Execution killed with signal 9 |
7 |
Runtime error |
67 ms |
131076 KB |
Execution killed with signal 9 |
8 |
Runtime error |
62 ms |
131076 KB |
Execution killed with signal 9 |
9 |
Runtime error |
61 ms |
131076 KB |
Execution killed with signal 9 |
10 |
Runtime error |
62 ms |
131076 KB |
Execution killed with signal 9 |
11 |
Runtime error |
74 ms |
131076 KB |
Execution killed with signal 9 |
12 |
Runtime error |
67 ms |
131076 KB |
Execution killed with signal 9 |
13 |
Runtime error |
67 ms |
131076 KB |
Execution killed with signal 9 |
14 |
Runtime error |
67 ms |
131076 KB |
Execution killed with signal 9 |
15 |
Runtime error |
68 ms |
131076 KB |
Execution killed with signal 9 |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
82 ms |
131076 KB |
Execution killed with signal 9 |
2 |
Runtime error |
83 ms |
131076 KB |
Execution killed with signal 9 |
3 |
Runtime error |
82 ms |
131076 KB |
Execution killed with signal 9 |
4 |
Incorrect |
21 ms |
10832 KB |
Unexpected end of file - int32 expected |
5 |
Incorrect |
17 ms |
11336 KB |
Unexpected end of file - int32 expected |
6 |
Incorrect |
26 ms |
11712 KB |
Unexpected end of file - int32 expected |
7 |
Incorrect |
30 ms |
12596 KB |
Unexpected end of file - int32 expected |
8 |
Incorrect |
43 ms |
14236 KB |
Unexpected end of file - int32 expected |
9 |
Incorrect |
57 ms |
16440 KB |
Unexpected end of file - int32 expected |
10 |
Incorrect |
60 ms |
17748 KB |
Unexpected end of file - int32 expected |
11 |
Incorrect |
76 ms |
16396 KB |
Unexpected end of file - int32 expected |
12 |
Incorrect |
75 ms |
18212 KB |
Unexpected end of file - int32 expected |
13 |
Incorrect |
75 ms |
17656 KB |
Unexpected end of file - int32 expected |
14 |
Incorrect |
74 ms |
17708 KB |
Unexpected end of file - int32 expected |
15 |
Incorrect |
81 ms |
19016 KB |
Unexpected end of file - int32 expected |
16 |
Incorrect |
80 ms |
18948 KB |
Unexpected end of file - int32 expected |
17 |
Incorrect |
90 ms |
18876 KB |
Unexpected end of file - int32 expected |