#include "bits/stdc++.h"
using namespace std;
const int MAXN = 2e5 + 10;
const int MOD = 1e9 + 7;
#define int unsigned long long
#define ll __int128
mt19937_64 rng((int)std::chrono::steady_clock::now().time_since_epoch().count());
int rnd(int x, int y) {
int u = uniform_int_distribution<int>(x, y)(rng); return u;
}
vector<int> adj[MAXN];
vector<int> adj2[MAXN];
int dist[MAXN];
bool cmp(int a, int b) {
return dist[a] < dist[b];
}
void solve(int tc) {
int n, m, q;
n = 100000;
q = 100000;
m = 200000;
//cin >> n >> m >> q;
int p[n];
for(int i=0; i<n; i++) p[i] = i;
for(int i=0; i<m; i++) {
int s, e;
s = rnd(0, n - 2);
e = rnd(s + 1, n - 1);
//cin >> s >> e;
s--, e--;
adj[s].push_back(e);
adj2[e].push_back(s);
}
for(int i=0; i<n; i++) {
dist[i] = 0;
for(int j=0; j<adj2[i].size(); j++) {
dist[i] = max(dist[i], dist[adj2[i][j]] + 1);
}
}
sort(p, p + n, cmp);
int pos[n];
for(int i=0; i<n; i++) pos[p[i]] = i;
vector<int> adj3[n];
for(int i=0; i<n; i++) {
for(int x: adj[i]) {
adj3[pos[i]].push_back(pos[x]);
}
}
for(int i=0; i<n; i++) {
adj[i].clear();
adj2[i].clear();
adj[i] = adj3[i];
}
int dp[n][n / 64 + 2];
for(int i=0; i<n; i++) {
for(int j=0; j<n/64 + 2; j++) {
dp[i][j] = 0;
}
dp[i][i / 64] = (1ull << (i & 63));
}
for(int i=0; i<n; i++) {
for(int j=0; j<adj2[i].size(); j++) {
for(int k=0; k<n/64 + 2; k++) { // O(m * n / 64). is this ka chang ti
dp[i][k] |= dp[adj2[i][j]][k];
}
}
}
int dist2[n];
for(int i=0; i<n; i++) dist2[pos[i]] = dist[i];
for(int i=0; i<n; i++) dist[i] = dist2[i];
for(int i=0; i<n; i++) cout << p[i] << " ";
cout << "\n";
for(int i=0; i<n; i++) cout << dist[i] << " ";
cout << "\n";
int minus[n+1];
for(int i=0; i<=n; i++) minus[i] = 0;
return;
while(q--) {
int t, y;
cin >> t >> y;
t--;
t = pos[t];
vector<int> e(y);
for(int j=0; j<y; j++) {
cin >> e[j];
e[j]--;
e[j] = pos[e[j]];
minus[dist[e[j]]]++;
}
int cur_mex = 0;
for(int i=0; i<=y; i++) {
int cnt = 0;
}
int64_t one = dist[t];
one -= cur_mex;
cout << "dist[t] = " << dist[t] << ", mex = " << cur_mex << ", res = " << one << '\n';
for(int j=0; j<y; j++) {
minus[dist[e[j]]]--;
}
}
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0);
int t = 1; //cin >> t;
for(int i=1; i<=t; i++) solve(i);
}
/*
12 17 10
1 2
2 3
3 4
1 5
2 6
3 7
4 8
5 6
6 7
7 8
5 9
6 10
7 11
8 12
9 10
10 11
11 12
6 3 1 7 12
3 7 1 2 3 4 5 6 7
11 3 1 3 5
9 2 1 9
8 4 1 2 3 4
1 1 1
12 0
10 3 1 6 10
11 8 2 3 5 6 7 9 10 11
8 7 2 3 4 5 6 7 8
*/
Compilation message
examination.cpp: In function 'void solve(long long unsigned int)':
examination.cpp:94:11: warning: unused variable 'cnt' [-Wunused-variable]
94 | int cnt = 0;
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
651 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
603 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
603 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
651 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |