QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#424091#7106. Infinite Parenthesis Sequenceucup-team3215Compile Error//C++204.3kb2024-05-28 21:46:002024-05-28 21:46:00

Judging History

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

  • [2024-05-28 21:46:00]
  • 评测
  • [2024-05-28 21:46:00]
  • 提交

answer

#include <array>
#include <deque>
#include <iostream>
#include <vector>

using namespace std;

struct Slope {
  deque<array<int, 2>> elem;
  int c[2];
};

int main() {
  cin.tie(0)->sync_with_stdio(0);
  for (int tc = (cin >> tc, tc); tc--; ) {
    string s; int q; cin >> s >> q;
    int n = s.size(), cu = count(s.begin(), s.end(), '(');
    for (auto& c: s) c = c == '(';
    vector<int> ans(q);
    vector<array<int, 3>> que;
    for (int i = 0; i < q; ++i) {
      int k, l, r; cin >> k >> l >> r; ++r;
      int l1 = (l % n + n) % n, r1 = (r % n + n) % n;
      ans[i] = (r - l - r1 + l1) / n * cu;
      if (l1) que.push_back({k, l1, ~i});
      if (r1) que.push_back({k, r1, i});
    }
    sort(que.rbegin(), que.rend());
    vector<Slope> slopes;
    if (Slope cur{}; 1)
    for (int i = 0; ; ++i) {
      if (i == n || cur.elem.size() && cur.elem.back()[0] == s[i] && cur.c[!s[i]]) {
        for (int s = 0; auto& [i, j]: cur.elem) j = s, s += i;
        slopes.push_back(cur);
        cur = {};
      }
      if (i == n) break;
      if (cur.elem.size() && cur.elem.back()[0] == s[i]) ++cur.c[s[i]];
      cur.elem.push_back({s[i]});
    }
    int k = 0;
    while (slopes.size() > 1) {
      for (int i = 0, j = 0, s = 0; que.size() && que.back()[0] == k; ++k) {
        auto [_, jj, t] = que.back(); que.pop_back();
        while (j + slopes[i].elem.size() <= jj) s += slopes[i].elem.back()[1] + slopes[i].elem.back()[0] - slopes[i].elem[0][1], j += slopes[i++].elem.size();
        int a = s + slopes[i].elem[jj - j][1] - slopes[i].elem[0][1];
        t < 0? ans[~t] -= a: ans[t] += a;
      }
      vector<array<int, 2>> fl(slopes.size());
      for (int i = 0; i < slopes.size(); ++i) {
        fl[i] = {slopes[i].elem[0][0], slopes[i].elem.back()[0]};
      }
      vector<Slope> nslopes;
      for (int i = 0; i < slopes.size(); ++i) {
        if (slopes[i].elem.size() == 1) {
          slopes[i].elem[0][0] = slopes[i].elem[0][0]? fl[i + 1 == slopes.size()? 0: i + 1][0]: (i? fl[i - 1]: fl.back())[1];
        } else if (slopes[i].c[1]) {
          auto shiftin = slopes[i].elem.back()[0]? fl[i + 1 == slopes.size()? 0: i + 1][0]: slopes[i].elem.end()[-2][0];
          slopes[i].c[1] -= slopes[i].elem[0][0] == slopes[i].elem[1][0];
          slopes[i].elem.pop_front();
          slopes[i].c[1] += slopes[i].elem.back()[0] == shiftin;
          slopes[i].elem.push_back({shiftin, slopes[i].elem.back()[1] + slopes[i].elem.back()[0]});
        } else {
          auto shiftin = slopes[i].elem[0][0]? slopes[i].elem[1][0]: (i? fl[i - 1]: fl.back())[1];
          slopes[i].c[0] -= slopes[i].elem.back()[0] == slopes[i].elem.end()[-2][0];
          slopes[i].elem.pop_back();
          slopes[i].c[0] += slopes[i].elem[0][0] == shiftin;
          slopes[i].elem.push_front({shiftin, slopes[i].elem[0][1] - shiftin});
        }
        if (nslopes.size() && (!nslopes.back().c[1] && !(nslopes.back().elem.back()[0] && slopes[i].elem[0][0]) && !slopes[i].c[1] ||
                               !nslopes.back().c[0] &&  (nslopes.back().elem.back()[0] || slopes[i].elem[0][0]) && !slopes[i].c[0])) {
          nslopes.back().c[0] += slopes[i].c[0] + !(nslopes.back().elem.back()[0] || slopes[i].elem[0][0]);
          nslopes.back().c[1] += slopes[i].c[1] +  (nslopes.back().elem.back()[0] && slopes[i].elem[0][0]);
          if (nslopes.back().elem.size() > slopes[i].elem.size()) {
            auto t = nslopes.back().elem.back()[1];
            for (auto& [x, _]: slopes[i].elem) nslopes.back().elem.push_back({x, t}), t += x;
          } else {
            auto t = slopes[i].elem.front()[1];
            for (int i = nslopes.back().elem.size(); i--; ) if (auto& [x, _] = nslopes.back().elem[i]; 1) {
              slopes[i].elem.push_front({x, t -= x});
            }
            swap(nslopes.back().elem, slopes[i].elem);
          }
        } else {
          nslopes.push_back(move(slopes[i]));
        }
      }
      swap(slopes, nslopes);
    }
    auto slope = move(slopes[0]);
    while (que.size()) {
      auto [kk, r, t] = que.back(); que.pop_back();
      int l = (kk - k) % n;
      if (slope.c[0]) l = (n - l) % n;
      r = (r + l) % n;
      int a = slope.elem[r][1] - slope.elem[l][1] + (r >= l? 0: cu);
      t < 0? ans[~t] -= a: ans[t] += a;
    }
    for (auto& x: ans) cout << x << '\n';
  }
}

Details

answer.code: In function ‘int main()’:
answer.code:17:28: error: ‘count’ was not declared in this scope
   17 |     int n = s.size(), cu = count(s.begin(), s.end(), '(');
      |                            ^~~~~
answer.code:28:5: error: ‘sort’ was not declared in this scope; did you mean ‘short’?
   28 |     sort(que.rbegin(), que.rend());
      |     ^~~~
      |     short