QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#354806#5110. SplitstreamnvmdavaRE 0ms0kbC++232.6kb2024-03-16 02:21:132024-03-16 02:21:14

Judging History

你现在查看的是最新测评结果

  • [2024-03-16 02:21:14]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2024-03-16 02:21:13]
  • 提交

answer

#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];

char cc[10005];
int xx[10005], yy[10005], zz[10005];
int help[10005];
int indeg[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);

  queue<int> que;
  rep(i, 0, n) {
    cin>>cc[i]>>xx[i]>>yy[i]>>zz[i];
    --xx[i]; --yy[i]; --zz[i];
    if(xx[i] == 0) que.push(i);
    if(cc[i] == 'M') {
      indeg[i] = 2;
      help[xx[i]] = i;
      help[yy[i]] = i;
    } else {
      indeg[i] = 1;
      help[xx[i]] = i;
    }
  }

  while(!que.empty()) {
    int x = xx[que.front()], y = yy[que.front()], z = zz[que.front()];
    char c = cc[que.front()];
    que.pop();
    if(c == 'S') {
      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];
      if(help[y] && --indeg[help[y]] == 0) que.push(help[y]);
      if(help[z] && --indeg[help[z]] == 0) que.push(help[z]);
    } else {
      arr[z] = new Node( arr[x] -> siz + arr[y] -> siz);
      arr[z] -> inp1 = arr[x];
      arr[z] -> inp2 = arr[y];
      if(help[z] && --indeg[help[z]] == 0) que.push(help[z]);
    }
  }

  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

output:


result: