QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#798667#9791. Intrusive DonkeyMisuki#RE 0ms3648kbC++209.4kb2024-12-04 15:53:132024-12-04 15:53:20

Judging History

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

  • [2024-12-04 15:53:20]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3648kb
  • [2024-12-04 15:53:13]
  • 提交

answer

#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cfenv>
#include <cfloat>
#include <chrono>
#include <cinttypes>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdarg>
#include <cstddef>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <initializer_list>
#include <iomanip>
#include <ios>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <streambuf>
#include <string>
#include <tuple>
#include <type_traits>
#include <variant>
#include <bit>
#include <compare>
#include <concepts>
#include <numbers>
#include <ranges>
#include <span>

#define int ll
#define INT128_MAX (__int128)(((unsigned __int128) 1 << ((sizeof(__int128) * __CHAR_BIT__) - 1)) - 1)
#define INT128_MIN (-INT128_MAX - 1)

#define clock chrono::steady_clock::now().time_since_epoch().count()

using namespace std;

template<class T1, class T2>
ostream& operator<<(ostream& os, const pair<T1, T2> pr) {
  return os << pr.first << ' ' << pr.second;
}
template<class T, size_t N>
ostream& operator<<(ostream& os, const array<T, N> &arr) {
  for(size_t i = 0; T x : arr) {
    os << x;
    if (++i != N) os << ' ';
  }
  return os;
}
template<class T>
ostream& operator<<(ostream& os, const vector<T> &vec) {
  for(size_t i = 0; T x : vec) {
    os << x;
    if (++i != size(vec)) os << ' ';
  }
  return os;
}
template<class T>
ostream& operator<<(ostream& os, const set<T> &s) {
  for(size_t i = 0; T x : s) {
    os << x;
    if (++i != size(s)) os << ' ';
  }
  return os;
}
template<class T1, class T2>
ostream& operator<<(ostream& os, const map<T1, T2> &m) {
  for(size_t i = 0; pair<T1, T2> x : m) {
    os << x;
    if (++i != size(m)) os << ' ';
  }
  return os;
}

#ifdef DEBUG
#define dbg(...) cerr << '(', _do(#__VA_ARGS__), cerr << ") = ", _do2(__VA_ARGS__)
template<typename T> void _do(T &&x) { cerr << x; }
template<typename T, typename ...S> void _do(T &&x, S&&...y) { cerr << x << ", "; _do(y...); }
template<typename T> void _do2(T &&x) { cerr << x << endl; }
template<typename T, typename ...S> void _do2(T &&x, S&&...y) { cerr << x << ", "; _do2(y...); }
#else
#define dbg(...)
#endif

using ll = long long;
using ull = unsigned long long;
using ldb = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
//#define double ldb

template<typename T> using min_heap = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using max_heap = priority_queue<T>;

template<ranges::forward_range rng, class T = ranges::range_value_t<rng>, class OP = plus<T>>
void pSum(rng &&v) {
  if (!v.empty())
    for(T p = v[0]; T &x : v | views::drop(1))
      x = p = OP()(p, x);
}
template<ranges::forward_range rng, class T = ranges::range_value_t<rng>, class OP>
void pSum(rng &&v, OP op) {
  if (!v.empty())
    for(T p = v[0]; T &x : v | views::drop(1))
      x = p = op(p, x);
}

template<ranges::forward_range rng>
void Unique(rng &v) {
  ranges::sort(v);
  v.resize(unique(v.begin(), v.end()) - v.begin());
}

template<ranges::random_access_range rng>
rng invPerm(rng p) {
  rng ret = p;
  for(int i = 0; i < ssize(p); i++)
    ret[p[i]] = i;
  return ret;
}

template<ranges::random_access_range rng, ranges::random_access_range rng2>
rng Permute(rng v, rng2 p) {
  rng ret = v;
  for(int i = 0; i < ssize(p); i++)
    ret[p[i]] = v[i];
  return ret;
}

template<bool directed>
vector<vector<int>> readGraph(int n, int m, int base) {
  vector<vector<int>> g(n);
  for(int i = 0; i < m; i++) {
    int u, v; cin >> u >> v;
    u -= base, v -= base;
    g[u].emplace_back(v);
    if constexpr (!directed)
      g[v].emplace_back(u);
  }
  return g;
}

template<class T>
void setBit(T &msk, int bit, bool x) {
  msk = (msk & ~(T(1) << bit)) | (T(x) << bit);
}
template<class T> void flipBit(T &msk, int bit) { msk ^= T(1) << bit; }
template<class T> bool getBit(T msk, int bit) { return msk >> bit & T(1); }

template<class T>
T floorDiv(T a, T b) {
  if (b < 0) a *= -1, b *= -1;
  return a >= 0 ? a / b : (a - b + 1) / b;
}
template<class T>
T ceilDiv(T a, T b) {
  if (b < 0) a *= -1, b *= -1;
  return a >= 0 ? (a + b - 1) / b : a / b;
}

template<class T> bool chmin(T &a, T b) { return a > b ? a = b, 1 : 0; }
template<class T> bool chmax(T &a, T b) { return a < b ? a = b, 1 : 0; }

template<class M, M(*Mid)(), M(*Mop)(const M&, const M&), class T, T(*Tid)(), T(*Top)(const T&, const T&), M(*act)(const M&, const T&)>
struct lazySegmentTree {
  int size;
  vector<M> data;
  vector<T> tag;

  lazySegmentTree(int _size) : size(_size), data(2 * size, Mid()), tag(size, Tid()) {}

  lazySegmentTree(vector<M> init) : size(ssize(init)), data(2 * size, Mid()), tag(size, Tid()) {
    ranges::copy(init, data.begin() + size);
    for(int i = size - 1; i > 0; i--)
      data[i] = Mop(data[i << 1], data[i << 1 | 1]);
  }

  void apply(int i, T x) {
    data[i] = act(data[i], x);
    if (i < size) tag[i] = Top(tag[i], x);
  }

  void push(unsigned i) {
    for(int s = (int)bit_width(i) - 1; s > 0; s--) {
      if (tag[i >> s] != Tid()) {
        apply(i >> (s - 1), tag[i >> s]);
        apply(i >> (s - 1) ^ 1, tag[i >> s]);
        tag[i >> s] = Tid();
      }
    }
  }

  void pull(int i) {
    while(i >>= 1) data[i] = Mop(data[i << 1], data[i << 1 | 1]);
  }

  int trunc(unsigned i) { return i >> countr_zero(i); }

  void set(int i, M x) {
    push(i += size);
    data[i] = x;
    pull(i);
  }

  M get(int i) { push(i += size); return data[i]; }

  void modify(int l, int r, T x) {
    if (l >= r or x == Tid()) return;
    push(trunc(l += size)), push(trunc(r += size) - 1);
    int l0 = l, r0 = r;
    for(; l < r; l >>= 1, r >>= 1) {
      if (l & 1) apply(l++, x);
      if (r & 1) apply(--r, x);
    }
    pull(trunc(l0)), pull(trunc(r0) - 1);
  }

  M query(int l, int r) {
    if (l >= r) return Mid();
    M L = Mid(), R = Mid();
    push(trunc(l += size)), push(trunc(r += size) - 1);
    for(; l < r; l >>= 1, r >>= 1) {
      if (l & 1) L = Mop(L, data[l++]);
      if (r & 1) R = Mop(data[--r], R);
    }
    return Mop(L, R);
  }

  int firstTrue(int i, function<bool(const M&)> f) {
    vector<int> idL, idR;
    push(trunc(i + size)), push(trunc(size << 1) - 1);
    for(int l = i + size, r = size << 1; l < r; l >>= 1, r >>= 1) {
      if (l & 1) idL.emplace_back(l++);
      if (r & 1) idR.emplace_back(--r);
    }
    idL.insert(idL.end(), idR.rbegin(), idR.rend());
    M pre = Mid();
    int v = -1;
    for(int j : idL) {
      if (f(Mop(pre, data[j]))) {
        v = j;
        break;
      } else {
        pre = Mop(pre, data[j]);
      }
    }
    if (v == -1) return size;
    while(v < size) {
      if (tag[v] != Tid()) {
        apply(v << 1, tag[v]);
        apply(v << 1 | 1, tag[v]);
        tag[v] = Tid();
      }
      if (f(Mop(pre, data[v << 1])))
        v = v << 1;
      else
        pre = Mop(pre, data[v << 1]), v = v << 1 | 1;
    }
    return v - size;
  }

  int lastTrue(int i, function<bool(const M&)> f) {
    vector<int> idL, idR;
    push(trunc(size)), push(trunc((i + 1) + size) - 1);
    for(int l = size, r = (i + 1) + size; l < r; l >>= 1, r >>= 1) {
      if (l & 1) idL.emplace_back(l++);
      if (r & 1) idR.emplace_back(--r);
    }
    idR.insert(idR.end(), idL.rbegin(), idL.rend());
    M suf = Mid();
    int v = -1;
    for(int j : idR) {
      if (f(Mop(data[j], suf))) {
        v = j;
        break;
      } else {
        suf = Mop(data[j], suf);
      }
    }
    if (v == -1) return -1;
    while(v < size) {
      if (tag[v] != Tid()) {
        apply(v << 1, tag[v]);
        apply(v << 1 | 1, tag[v]);
        tag[v] = Tid();
      }
      if (f(Mop(data[v << 1 | 1], suf)))
        v = v << 1 | 1;
      else
        suf = Mop(data[v << 1 | 1], suf), v = v << 1;
    }
    return v - size;
  }
};

ll Mop(const ll &a, const ll &b) { return a + b; }
ll Mid() { return 0ll; }
ll Top(const ll &a, const ll &b) { return a * b; }
ll Tid() { return 1ll; }
ll act(const ll &m, const ll &t) { return m * t; }

signed main() {
  ios::sync_with_stdio(false), cin.tie(NULL);

  int n, q; cin >> n >> q;
  string s; cin >> s;

  lazySegmentTree<ll, Mid, Mop, ll, Tid, Top, act> st(vector<ll>(n, 1));

  while(q--) {
    int op; cin >> op;
    if (op == 1) {
      int l, r; cin >> l >> r;
      l--;
      int L = st.firstTrue(0, [&](const ll &x) { return x > l; });
      int R = st.firstTrue(0, [&](const ll &x) { return x > r - 1; });
      dbg(L, R);
      if (L + 1 < R) st.modify(L + 1, R, 2);

      if (L == R) {
        st.set(L, st.get(L) + (r - l));
      } else {
        st.set(R, 2 * st.get(R) - (st.query(0, R + 1) - r));
        st.set(L, st.get(L) + (st.query(0, L + 1) - l));
      }
      //for(int i = 0; i < n; i++)
        //cout << st.get(i) << " \n"[i + 1 == n];
    } else {
      int i; cin >> i;
      i--;
      dbg(st.firstTrue(0, [&](const ll &x) { return x > i; }));
      cout << s[st.firstTrue(0, [&](const ll &x) { return x > i; })] << '\n';
    }
  }

  return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3648kb

input:

4 7
abac
2 2
2 3
1 2 3
2 3
2 4
2 5
2 6

output:

b
a
b
a
a
c

result:

ok 6 lines

Test #2:

score: 0
Accepted
time: 0ms
memory: 3576kb

input:

5 4
shrek
1 1 2
2 7
1 1 7
2 7

output:

k
h

result:

ok 2 lines

Test #3:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

4 7
abac
2 2
2 3
1 2 3
2 3
2 4
2 5
2 6

output:

b
a
b
a
a
c

result:

ok 6 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 3580kb

input:

5 4
shrek
1 1 2
2 7
1 1 7
2 7

output:

k
h

result:

ok 2 lines

Test #5:

score: 0
Accepted
time: 0ms
memory: 3588kb

input:

3 55
vfe
1 2 3
1 2 2
1 3 5
2 4
1 1 2
2 9
2 7
2 5
1 10 10
1 1 1
2 9
1 8 12
2 8
1 7 10
2 1
1 5 6
1 1 4
1 20 24
1 14 32
1 19 38
2 48
1 56 64
2 58
2 19
1 64 72
1 36 86
2 11
1 117 124
2 38
2 108
2 85
1 112 118
2 153
2 40
2 114
2 80
1 11 18
2 27
2 73
1 159 162
2 84
1 130 164
2 163
2 65
1 150 156
1 101 109...

output:

f
e
f
f
f
f
v
f
e
f
f
f
e
e
e
f
e
e
f
e
e
e
f
e
f
e
v

result:

ok 27 lines

Test #6:

score: -100
Runtime Error

input:

60 51
ranhfkbjhkxckkcbhgsspsjcbjgpwcfvmqqlvlfualndmqqsihsfdyqviowu
2 53
2 37
2 33
2 60
1 1 32
2 44
1 87 92
1 7 77
1 56 86
2 17
1 128 184
1 26 159
2 323
2 55
1 24 316
1 435 652
2 316
2 444
1 819 868
2 27
2 912
2 313
1 555 576
1 510 942
1 1118 1269
2 365
2 84
1 595 650
2 1468
2 258
1 1557 1607
2 938
1...

output:


result: