QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#375261 | #5110. Splitstream | Anish_aak | RE | 1ms | 3588kb | C++14 | 3.5kb | 2024-04-03 04:12:34 | 2024-04-03 04:12:34 |
Judging History
answer
#include <bits/stdc++.h>
// #pragma comment(linker, "/STACK:268435456");,
using namespace std;
#define int long long
#define double long double
#define pb push_back
#define all(t) (t).begin(), (t).end()
#define rep(i,j) for(int i = 0; i < (j); ++i)
#define rrep(i,j) for(int i = (j)-1; i >= 0; --i)
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
const char nl = '\n';
const double eps = 1e-6;
const int N = 1e5, mod = 1e9 + 7, inf = 1e18;
int n;
vector<bool> visited;
vector<int> ans;
vector<vector<int>> adj;
vector<vector<int>> par;
void dfs(int v) {
visited[v] = true;
for (int u : adj[v]) {
if (!visited[u])
dfs(u);
}
ans.push_back(v);
}
void topological_sort() {
visited.assign(2*n+1, false);
ans.clear();
for (int i = 1; i <= 2*n; ++i) {
if (!visited[i])
dfs(i);
}
reverse(ans.begin(), ans.end());
}
void solve()
{
int m, q; cin >> m >> n >> q;
vector<int> sz(2 * n + 1, 0);
adj.resize(2 * n + 1);
par.resize(2 * n + 1);
par[1].pb(-1);
rep(i, n) {
char c; cin >> c;
int x, y, z; cin >> x >> y >> z;
if(c == 'S') {
adj[x].pb(y);
adj[x].pb(z);
par[y].pb(x);
par[z].pb(x);
} else {
adj[x].pb(z);
adj[y].pb(z);
par[z].pb(x);
par[z].pb(y);
}
}
topological_sort();
sz[1] = m;
for(auto i: ans) {
if(adj[i].size() == 2) {
sz[adj[i][0]] = (sz[i] + 1)/2;
sz[adj[i][1]] = sz[i]/2;
} else if(adj[i].size() == 1) {
sz[adj[i][0]] += sz[i];
}
}
rep(i, q) {
int x, y; cin >> x >> y;
int node = x, ind = y;
if(ind > sz[node]) {
cout << "none\n";
continue;
}
while(par[node][0] != -1) {
assert(ind <= sz[node]);
if(par[node].size() == 2) {
assert(sz[node] == sz[par[node][0]] + sz[par[node][1]]);
int overlap = min(sz[par[node][0]], sz[par[node][1]]) * 2;
if(ind <= overlap) {
node = par[node][(ind + 1) % 2];
ind = (ind + 1)/2;
} else {
if(sz[par[node][0]] < sz[par[node][1]]) {
node = par[node][1];
} else {
node = par[node][0];
}
ind = ind - overlap/2;
}
} else if(par[node].size() == 1) {
int prev = node;
node = par[node][0];
assert(adj[node].size() == 2);
int wh = 0;
if(adj[node][1] == prev) wh = 1;
ind = ind * 2 - (wh ^ 1);
} else {
assert(0);
}
}
cout << ind << nl;
}
}
int32_t main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.precision(numeric_limits<double>::max_digits10);
cout << setprecision(15) << fixed;
#ifdef aak_local
freopen("/Users/aak/Desktop/Comding/Competitive/input.txt","r",stdin);
freopen("/Users/aak/Desktop/Comding/Competitive/output.txt","w",stdout);
#endif
int tt = 1;
// cin >> tt;
for(int i = 1; i <= tt; ++i)
{
// cout << "Case #" << i << ": ";
solve();
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 3588kb
input:
5 8 26 M 8 9 13 S 2 4 5 S 1 2 3 M 6 5 8 S 4 9 10 S 10 14 15 S 3 6 7 S 7 11 12 2 3 2 4 3 2 3 3 4 2 4 3 5 1 5 2 6 1 6 2 7 1 7 2 8 2 8 3 9 1 9 2 10 1 10 2 11 1 11 2 12 1 13 3 13 4 14 1 14 2 15 1
output:
5 none 4 none 5 none 3 none 2 none 4 none 3 none 1 none 5 none 4 none none 3 none 5 none none
result:
ok 26 lines
Test #2:
score: -100
Runtime Error
input:
1000000000 8191 1000 S 1 2 3 S 2 4 5 S 3 6 7 S 4 8 9 S 5 10 11 S 6 12 13 S 7 14 15 S 8 16 17 S 9 18 19 S 10 20 21 S 11 22 23 S 12 24 25 S 13 26 27 S 14 28 29 S 15 30 31 S 16 32 33 S 17 34 35 S 18 36 37 S 19 38 39 S 20 40 41 S 21 42 43 S 22 44 45 S 23 46 47 S 24 48 49 S 25 50 51 S 26 52 53 S 27 54 55...