QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#110108 | #2001. Tropical Garden | minhcool# | 69 | 70ms | 73504kb | C++14 | 3.3kb | 2023-05-31 15:37:17 | 2024-05-31 13:52:30 |
Judging History
answer
#include "garden.h"
#include "gardenlib.h"
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
//#define ll long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
/*
Algo: We have 2n nodes (i, 0/1 - is last node the largest)
Just for lmao
*/
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef pair<ii, ii> iiii;
const ll N = 3e5 + 5;
const ll oo = 1e18 + 7, mod = 1e9 + 7;
mt19937 rng(1);
ll rnd(ll l, ll r){
ll temp = rng() % (r - l + 1);
return abs(temp) + l;
}
ll n, m, p, q;
vector<ll> Adj[N];
// cycles that node u can get
vector<ii> cyc[N][2];
//map<ii, ll> mp;
ii nxt[N][2];
ll mn_dist[N][2];
vector<ii> Adj2[N][2];
void count_routes(int N, int M, int P, int R[][2], int Q, int G[]){
n = N, m = M, p = P;
for(ll i = 0; i < m; i++){
Adj[R[i][0]].pb(R[i][1]);
Adj[R[i][1]].pb(R[i][0]);
//mp[{min(R[i][0], R[i][1]), m}
}
for(ll i = 0; i < n; i++){
// last trail is the best in all trails from i -> need to choose second if there is one
if(Adj[i].size() >= 2) nxt[i][1] = {Adj[i][1], (Adj[Adj[i][1]][0] == i)};
else nxt[i][1] = {Adj[i][0], (Adj[Adj[i][0]][0] == i)};
nxt[i][0] = {Adj[i][0], (Adj[Adj[i][0]][0] == i)};
}
for(ll i = 0; i < n; i++){
for(ll j = 0; j < 2; j++){
Adj2[nxt[i][j].fi][nxt[i][j].se].pb({i, j});
}
}
// finding the cycle for (p, 0)
ii itr = {p, 0};
ll len = 0;
while((!len || itr != make_pair(p, 0LL)) && len <= 2 * n){
len++;
itr = nxt[itr.fi][itr.se];
}
if(len > 2 * n) len = oo;
for(ll i = 0; i < n; i++) mn_dist[i][0] = mn_dist[i][1] = oo;
mn_dist[p][0] = 0;
queue<ii> bfs;
bfs.push({p, 0});
while(!bfs.empty()){
ii u = bfs.front();
bfs.pop();
for(auto it : Adj2[u.fi][u.se]){
if(mn_dist[it.fi][it.se] != oo) continue;
mn_dist[it.fi][it.se] = mn_dist[u.fi][u.se] + 1;
bfs.push(it);
}
}
for(ll i = 0; i < n; i++){
for(ll j = 0; j < 2; j++){
if(mn_dist[i][j] == oo) continue;
cyc[i][j].pb({mn_dist[i][j], len});
}
}
itr = {p, 1};
len = 0;
while((!len || itr != make_pair(p, 1LL)) && len <= 2 * n){
len++;
itr = nxt[itr.fi][itr.se];
}
if(len > 2 * n) len = oo;
for(ll i = 0; i < n; i++) mn_dist[i][0] = mn_dist[i][1] = oo;
mn_dist[p][1] = 0;
//queue<ii> bfs;
bfs.push({p, 1});
//cout << "OKAY\n";
while(!bfs.empty()){
ii u = bfs.front();
bfs.pop();
for(auto it : Adj2[u.fi][u.se]){
if(mn_dist[it.fi][it.se] != oo) continue;
mn_dist[it.fi][it.se] = mn_dist[u.fi][u.se] + 1;
bfs.push(it);
}
}
for(ll i = 0; i < n; i++){
for(ll j = 0; j < 2; j++){
if(mn_dist[i][j] == oo) continue;
cyc[i][j].pb({mn_dist[i][j], len});
//cout << i << " " << j << " " << mn_dist[i][j] << " " << len << "\n";
}
}
// exit(0);
for(ll i = 0; i < Q; i++){
ll tol = 0;
G[i]--;
for(ll j = 0; j < n; j++){
ii temp = {Adj[j][0], (Adj[Adj[j][0]][0] == j)};
//cout << temp.fi << " " << temp.se << "\n";
//cout << j << " " << Adj[j][0] << "\n";
//continue;
bool ck = 0;
for(auto it : cyc[temp.fi][temp.se]) ck |= ((G[i] >= it.fi) && !((G[i] - it.fi) % it.se));
tol += ck;
}
//cout << i << " " << tol << "\n";
answer(tol);
if(n >= 100000 && Q > 1) exit(0);
}
}
详细
Subtask #1:
score: 49
Accepted
Test #1:
score: 49
Accepted
time: 0ms
memory: 42996kb
input:
780 780 0 1 0 0 2 2 3 3 1 4 1 5 4 6 5 7 6 8 7 9 8 10 9 11 10 12 11 13 12 14 13 15 14 16 15 17 16 18 17 19 18 20 19 21 20 22 21 23 22 24 23 25 24 26 25 27 26 28 27 29 28 30 29 31 30 32 31 33 32 34 33 35 34 36 35 37 36 38 37 39 38 40 39 41 40 42 41 43 42 44 43 45 44 46 45 47 46 48 47 49 48 50 49 51 50...
output:
Correct.
Test #2:
score: 0
Accepted
time: 0ms
memory: 44816kb
input:
950 950 0 1 0 0 2 2 3 3 1 4 1 5 4 6 5 7 6 8 7 9 8 10 9 11 10 12 11 13 12 14 13 15 14 16 15 17 16 18 17 19 18 20 19 21 20 22 21 23 22 24 23 25 24 26 25 27 26 28 27 29 28 30 29 31 30 32 31 33 32 34 33 35 34 36 35 37 36 38 37 39 38 40 39 41 40 42 41 43 42 44 43 45 44 46 45 47 46 48 47 49 48 50 49 51 50...
output:
Correct.
Test #3:
score: 0
Accepted
time: 7ms
memory: 44132kb
input:
999 1099 0 1 0 0 2 2 3 3 1 4 1 5 4 6 5 7 6 8 7 9 8 10 9 11 10 12 11 13 12 14 13 15 14 16 15 17 16 18 17 19 18 20 19 21 20 22 21 23 22 24 23 25 24 26 25 27 26 28 27 29 28 30 29 31 30 32 31 33 32 34 33 35 34 36 35 37 36 38 37 39 38 40 39 41 40 42 41 43 42 44 43 45 44 46 45 47 46 48 47 49 48 50 49 51 5...
output:
Correct.
Test #4:
score: 0
Accepted
time: 3ms
memory: 43596kb
input:
45 44 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 1 100 1
output:
Correct.
Test #5:
score: 0
Accepted
time: 0ms
memory: 42932kb
input:
17 46 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 11 16 14 2 13 1 0 6 3 14 0 15 14 0 12 0 5 3 13 16 8 13 5 16 14 10 10 13 9 12 16 4 11 1 5 0 12 8 8 2 12 16 13 7 9 1 10 3 15 5 15 12 12 7 7 10 9 4 10 12 1 100 3
output:
Correct.
Test #6:
score: 0
Accepted
time: 7ms
memory: 45440kb
input:
1000 2000 7 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 0 0 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 ...
output:
Correct.
Test #7:
score: 0
Accepted
time: 6ms
memory: 44116kb
input:
70 170 10 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 ...
output:
Correct.
Test #8:
score: 0
Accepted
time: 4ms
memory: 44088kb
input:
1000 1000 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 0 8 0 9 0 10 2 11 6 12 11 13 9 14 2 15 3 16 14 17 15 18 5 19 2 20 3 21 1 22 2 23 4 24 9 25 2 26 17 27 15 28 5 29 20 30 12 31 24 32 28 33 26 34 25 35 32 36 8 37 16 38 2 39 18 40 3 41 38 42 15 43 39 44 18 45 23 46 37 47 10 48 24 49 47 50 40 51 4 52 19 53 50 54...
output:
Correct.
Test #9:
score: 0
Accepted
time: 8ms
memory: 44620kb
input:
1000 8000 0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 0 13 4 14 0 15 10 16 5 17 6 18 14 19 2 20 6 21 10 22 18 23 18 24 0 25 10 26 22 27 11 28 5 29 16 30 14 31 2 32 0 33 0 34 9 35 24 36 34 37 34 38 37 39 15 40 22 41 1 42 32 43 10 44 18 45 35 46 21 47 45 48 32 49 16 50 30 51 44 52 31 53 ...
output:
Correct.
Subtask #2:
score: 20
Accepted
Dependency #1:
100%
Accepted
Test #10:
score: 20
Accepted
time: 3ms
memory: 44428kb
input:
100 100 13 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 0 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 10 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 27 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 ...
output:
Correct.
Test #11:
score: 0
Accepted
time: 44ms
memory: 66288kb
input:
135000 142500 2 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 65899 68039 16 0 17 18 18 19 19 20 20 21 21 22 125073 94485 22 23 23 24 24 25 25 26 26 27 27 28 77287 19161 28 29 29 30 30 31 31 32 32 33 33 34 34 17 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 ...
output:
Correct.
Test #12:
score: 0
Accepted
time: 62ms
memory: 73504kb
input:
136500 148500 5 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 16375 41566 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 0 23 3 24 10 25 22 26 14 27 25 28 23 29 20 30 9 31 2 32 0 33 23 34 32 35 7 36 6 37 9 38 7 39 31 87416 33922 40 5 41 29 42 2 43 15 44 21 45 18 46 42 47 36 48...
output:
Correct.
Test #13:
score: 0
Accepted
time: 46ms
memory: 62640kb
input:
91500 136500 20 89996 82811 0 1 30077 17428 46967 14606 1 2 2 3 3 4 4 5 20321 91440 5 6 6 7 25893 61981 7 8 84360 43614 8 9 68077 71226 9 10 23469 60159 10 11 11 12 50911 81003 12 13 4323 50214 90721 74352 13 14 75252 66390 14 15 3776 36420 15 16 16 17 58288 11702 17 18 18 19 49600 3263 19 20 20 21 ...
output:
Correct.
Test #14:
score: 0
Accepted
time: 40ms
memory: 62848kb
input:
76500 136498 0 56932 48973 1 0 56331 57161 2 0 17168 73563 3736 61655 16253 38330 3 1 4 3 5 1 4642 11834 26074 3018 12112 75650 58168 23812 1684 37453 6 0 14001 44650 54304 2234 53135 45296 56151 9690 7 6 8 7 9 2 10 5 34373 20594 11 5 12 2 64635 19590 63284 21071 13 2 14 10 15 1 16 15 17 7 68264 392...
output:
Correct.
Test #15:
score: 0
Accepted
time: 46ms
memory: 66752kb
input:
150000 150000 200 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 5...
output:
Correct.
Test #16:
score: 0
Accepted
time: 8ms
memory: 47464kb
input:
22500 22500 200 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 ...
output:
Correct.
Test #17:
score: 0
Accepted
time: 12ms
memory: 50928kb
input:
37500 52500 500 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 ...
output:
Correct.
Test #18:
score: 0
Accepted
time: 34ms
memory: 68612kb
input:
85183 85182 13 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 5...
output:
Correct.
Test #19:
score: 0
Accepted
time: 49ms
memory: 65672kb
input:
135000 142500 2 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 0 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 17 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 5...
output:
Correct.
Test #20:
score: 0
Accepted
time: 70ms
memory: 73496kb
input:
136500 148500 5 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 0 23 0 24 17 25 13 26 17 27 16 28 16 29 9 30 7 31 5 32 7 33 11 34 26 35 19 36 35 37 6 38 36 39 31 40 25 41 10 42 34 43 4 44 34 45 33 46 0 47 31 48 29 49 8 50 6 51 20 52...
output:
Correct.
Test #21:
score: 0
Accepted
time: 47ms
memory: 63172kb
input:
91500 136500 20 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 37 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 ...
output:
Correct.
Test #22:
score: 0
Accepted
time: 31ms
memory: 63664kb
input:
76500 136499 0 1 0 2 1 3 2 4 1 5 0 6 3 7 6 8 2 9 6 10 2 11 1 12 10 13 12 14 4 15 8 16 9 17 13 18 10 19 8 20 16 21 7 22 12 23 21 24 2 25 14 26 25 27 11 28 8 29 11 30 14 31 8 32 23 33 25 34 13 35 30 36 12 37 34 38 31 39 19 40 31 41 6 42 33 43 2 44 23 45 36 46 24 47 20 48 36 49 1 50 18 51 33 52 24 53 4...
output:
Correct.
Test #23:
score: 0
Accepted
time: 17ms
memory: 50768kb
input:
37500 52500 500 13868 25474 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 17587 629 8 9 9 10 19816 31812 11107 8848 28455 3355 10 11 11988 2929 11 12 12 13 13 14 14 15 36479 21472 2068 20945 15 16 16 17 17 18 16477 36228 18 19 19 20 24507 32786 24966 24172 20 21 21 22 22 23 23 24 24 25 24933 29140 25 26 7114 1900...
output:
Correct.
Subtask #3:
score: 0
Wrong Answer
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Test #24:
score: 31
Accepted
time: 3ms
memory: 44684kb
input:
100 100 13 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 0 10 11 11 12 12 13 13 14 14 15 15 16 16 17 17 18 18 19 19 20 20 21 21 22 22 23 23 24 24 25 25 26 26 10 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 35 35 36 36 27 37 38 38 39 39 40 40 41 41 42 42 43 43 44 44 45 45 46 46 47 47 48 48 49 49 50 50 51 51 ...
output:
Correct.
Test #25:
score: -31
Wrong Answer
time: 50ms
memory: 64136kb
input:
135000 142500 2 0 1 78631 69685 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10 10 11 11 12 12 13 13 14 14 15 15 16 16 0 17 18 116459 101820 18 19 19 20 20 21 32482 16785 21 22 22 23 23 24 24 25 25 26 26 27 27 28 28 29 29 30 30 31 31 32 32 33 33 34 34 17 89461 85481 35 36 36 37 37 38 3105 74349 38 39 39 40 40 ...
output:
Unauthorized output