QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#354801 | #5110. Splitstream | nvmdava | RE | 0ms | 0kb | C++23 | 2.2kb | 2024-03-16 02:05:11 | 2024-03-16 02:05:12 |
answer
// problem-url: https://contest.ucup.ac/contest/1540/problem/8332
#if not LOCAL
#define NDEBUG 1
#endif
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(auto i = a; i < (b); ++i)
#define down(x, a) for (auto x = a; x--;)
#define all(x) begin(x), end(x)
#define sz(x) int(size(x))
#define let auto const
using ll = long long;
using lint = ll;
using pii = pair<int, int>;
using vi = vector<int>;
struct Node {
Node *inp1 = nullptr, *inp2 = nullptr;
int siz;
bool isLe = false;
Node(int siz, bool isLe = false) : siz(siz), isLe(isLe){}
};
Node* arr[10005];
int main() {
cin.tie(0)->sync_with_stdio(0);
cin.exceptions(cin.failbit);
int m, n, q;
cin>>m>>n>>q;
arr[0] = new Node(m);
rep(i, 0, n) {
char c;
int x, y, z;
cin>>c>>x>>y>>z;
--x; --y; --z;
if(c == 'S') {
assert(arr[x] != nullptr);
assert(arr[y] == nullptr && arr[z] == nullptr);
arr[y] = new Node( (arr[x] -> siz + 1 ) / 2, true);
arr[z] = new Node( (arr[x] -> siz) / 2);
arr[y] -> inp1 = arr[x];
arr[z] -> inp1 = arr[x];
} else {
assert(arr[x] != nullptr && arr[y] != nullptr);
assert(arr[z] == nullptr);
arr[z] = new Node( arr[x] -> siz + arr[y] -> siz);
arr[z] -> inp1 = arr[x];
arr[z] -> inp2 = arr[y];
}
}
while(q--) {
int x, k;
cin>>x>>k;
--x;
Node *cur = arr[x];
while(cur != arr[0]) {
// cout<<(cur -> siz)<<' '<<cur -> inp1 -> siz<<' '<<cur -> inp2 -> siz<<'\n';
if(cur -> inp2 == nullptr) {
k = k * 2 - (cur -> isLe == true);
cur = cur -> inp1;
} else {
if(k <= 2 * min(cur -> inp1 -> siz, cur -> inp2 -> siz)) {
if(k % 2 == 1) {
cur = cur -> inp1;
k = (k + 1) / 2;
} else {
cur = cur -> inp2;
k = k / 2;
}
} else {
k -= min(cur -> inp1 -> siz, cur -> inp2 -> siz);
if(cur -> inp1 -> siz > cur -> inp2 -> siz) {
cur = cur -> inp1;
} else {
cur = cur -> inp2;
}
}
}
}
if(k > m) cout<<"none\n";
else cout<<k<<'\n';
}
}
详细
Test #1:
score: 0
Runtime Error
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