QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#354807#5110. SplitstreamnvmdavaRE 0ms3692kbC++232.8kb2024-03-16 02:26:272024-03-16 02:26:27

Judging History

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

  • [2024-03-16 02:26:27]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3692kb
  • [2024-03-16 02:26:27]
  • 提交

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, 10005) help[i] = -1;
  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') {
      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];
      if(help[z] != -1 && --indeg[help[y]] == 0) que.push(help[y]);
      if(help[z] != -1 && --indeg[help[z]] == 0) que.push(help[z]);
    } 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];
      if(help[z] != -1 && --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: 100
Accepted
time: 0ms
memory: 3692kb

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...

output:


result: