QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#376892#6509. Not Another Range Query ProblemFido_PuppyWA 0ms11608kbC++232.6kb2024-04-04 18:15:502024-04-04 18:15:52

Judging History

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

  • [2024-04-04 18:15:52]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:11608kb
  • [2024-04-04 18:15:50]
  • 提交

answer

#include <bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back
#define MP make_pair
#define MT make_tuple
#define IT iterator
#define fi first
#define se second
#define For(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define Rep(i, a, b) for (int i = (int)(a); i >= (int)(b); --i)
#define CLR(a, v) memset(a, v, sizeof(a))
#define CPY(a, b) memcpy(a, b, sizeof(a))
#define debug cerr << "ztxakking\n"
#define y0 ztxaknoi
#define y1 ztxakioi
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using uint = unsigned int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using vi = vector<int>;
template<typename T>
using V = vector<T>;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 5e5 + 7;
int n, q, t[N], ans[N];
string a;
void add(int x, int k) {
  for (; x <= n; x += x & -x) t[x] += k;
}
int qry(int x) {
  int ans = 0;
  for (; x; x -= x & -x) ans += t[x];
  return ans;
}
V<tuple<int, int, int>> v[N];
bitset<N> vis;
int pre[N], nxt[N];
void del(int u) {
  nxt[pre[u]] = nxt[u], pre[nxt[u]] = pre[u];
}
set<int> A, B;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> q >> a, a = '@' + a + '@';
  For(i, 1, q) {
    int l, r, k; cin >> l >> r >> k;
    if (!k) ans[i] = r - l + 1; else v[k].eb(l, r, i);
  }
  nxt[0] = 1, pre[n + 1] = n;
  For(i, 1, n) pre[i] = i - 1, nxt[i] = i + 1;
  A.clear(), vis.reset();
  For(i, 1, n) if (a[i] != a[i - 1]) A.insert(i);
  For(i, 1, n) add(i, 1);
  For(i, 1, n) {
    B.clear();
    for (int u : A) {
      add(u, -1), del(u), vis[u] = 1;
      if (B.find(u) != B.end()) B.erase(u);
      if (nxt[u] < n) {
        if (!vis[nxt[u]] && a[nxt[u]] != a[pre[u]]) B.insert(nxt[u]);
        else if (B.find(nxt[u]) != B.end()) B.erase(nxt[u]);
      }
    }
    A.swap(B);
    for (auto [l, r, j] : v[i]) ans[j] = qry(r);
  }
  CLR(t, 0);
  nxt[0] = 1, pre[n + 1] = n;
  For(i, 1, n) pre[i] = i - 1, nxt[i] = i + 1;
  A.clear(), vis.reset();
  For(i, 1, n) if (a[i] != a[i + 1]) A.insert(i);
  For(i, 1, n) add(i, 1);
  For(i, 1, n) {
    B.clear();
    for (int u : A) {
      add(u, -1), del(u), vis[u] = 1;
      if (B.find(u) != B.end()) B.erase(u);
      if (pre[u]) {
        if (!vis[pre[u]] && a[pre[u]] != a[nxt[u]]) B.insert(pre[u]);
        else if (B.find(pre[u]) != B.end()) B.erase(pre[u]);
      }
    }
    A.swap(B);
    for (auto [l, r, j] : v[i]) ans[j] -= qry(l);
  }
  For(i, 1, q) cout << max(0, ans[i]) << '\n';
  return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 11608kb

input:

9 7
100110001
2 5 1
3 6 1
4 8 2
2 7 1
1 9 1
1 9 0
1 9 8

output:

1
1
1
2
4
9
0

result:

wrong answer 1st numbers differ - expected: '2', found: '1'