QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#282185#7872. 崩坏天际线hos_lyric#0 6587ms5012kbC++147.1kb2023-12-11 16:04:022024-07-04 03:12:29

Judging History

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

  • [2024-07-04 03:12:29]
  • 评测
  • 测评结果:0
  • 用时:6587ms
  • 内存:5012kb
  • [2023-12-11 16:04:02]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")

////////////////////////////////////////////////////////////////////////////////
template <unsigned M_> struct ModInt {
  static constexpr unsigned M = M_;
  unsigned x;
  constexpr ModInt() : x(0U) {}
  constexpr ModInt(unsigned x_) : x(x_ % M) {}
  constexpr ModInt(unsigned long long x_) : x(x_ % M) {}
  constexpr ModInt(int x_) : x(((x_ %= static_cast<int>(M)) < 0) ? (x_ + static_cast<int>(M)) : x_) {}
  constexpr ModInt(long long x_) : x(((x_ %= static_cast<long long>(M)) < 0) ? (x_ + static_cast<long long>(M)) : x_) {}
  ModInt &operator+=(const ModInt &a) { x = ((x += a.x) >= M) ? (x - M) : x; return *this; }
  ModInt &operator-=(const ModInt &a) { x = ((x -= a.x) >= M) ? (x + M) : x; return *this; }
  ModInt &operator*=(const ModInt &a) { x = (static_cast<unsigned long long>(x) * a.x) % M; return *this; }
  ModInt &operator/=(const ModInt &a) { return (*this *= a.inv()); }
  ModInt pow(long long e) const {
    if (e < 0) return inv().pow(-e);
    ModInt a = *this, b = 1U; for (; e; e >>= 1) { if (e & 1) b *= a; a *= a; } return b;
  }
  ModInt inv() const {
    unsigned a = M, b = x; int y = 0, z = 1;
    for (; b; ) { const unsigned q = a / b; const unsigned c = a - q * b; a = b; b = c; const int w = y - static_cast<int>(q) * z; y = z; z = w; }
    assert(a == 1U); return ModInt(y);
  }
  ModInt operator+() const { return *this; }
  ModInt operator-() const { ModInt a; a.x = x ? (M - x) : 0U; return a; }
  ModInt operator+(const ModInt &a) const { return (ModInt(*this) += a); }
  ModInt operator-(const ModInt &a) const { return (ModInt(*this) -= a); }
  ModInt operator*(const ModInt &a) const { return (ModInt(*this) *= a); }
  ModInt operator/(const ModInt &a) const { return (ModInt(*this) /= a); }
  template <class T> friend ModInt operator+(T a, const ModInt &b) { return (ModInt(a) += b); }
  template <class T> friend ModInt operator-(T a, const ModInt &b) { return (ModInt(a) -= b); }
  template <class T> friend ModInt operator*(T a, const ModInt &b) { return (ModInt(a) *= b); }
  template <class T> friend ModInt operator/(T a, const ModInt &b) { return (ModInt(a) /= b); }
  explicit operator bool() const { return x; }
  bool operator==(const ModInt &a) const { return (x == a.x); }
  bool operator!=(const ModInt &a) const { return (x != a.x); }
  friend std::ostream &operator<<(std::ostream &os, const ModInt &a) { return os << a.x; }
};
////////////////////////////////////////////////////////////////////////////////

constexpr unsigned MO = 998244353;
using Mint = ModInt<MO>;


// root: min (tie-break: left)
struct MinCartesianTree {
  int n, rt;
  vector<int> par, lef, rig;
  template <class T> void build(int n_, T *as) {
    assert(n_ >= 1);
    n = n_;
    rt = 0;
    par.assign(n, -1);
    lef.assign(n, -1);
    rig.assign(n, -1);
    int top = 0;
    vector<int> stack(n, 0);
    for (int u = 1; u < n; ++u) {
      if (as[stack[top]] > as[u]) {  // >
        for (; top >= 1 && as[stack[top - 1]] > as[u]; --top) {}  // >
        if (top == 0) {
          rt = par[lef[u] = stack[top]] = u;
        } else {
          par[lef[u] = stack[top]] = u;
          rig[par[u] = stack[top - 1]] = u;
        }
        stack[top] = u;
      } else {
        rig[par[u] = stack[top]] = u;
        stack[++top] = u;
      }
    }
  }
  template <class T> void build(const T &as) {
    build(as.size(), as.data());
  }
};


int N, Q;
vector<int> O, L, R, X;


namespace brute {
vector<int> qs;
MinCartesianTree ct;
Mint dfs(int l, int r, int u) {
  Mint ret = 0;
  if (l < u && u < r && qs[u] < Q) {
    ret += dfs(l, u, ct.lef[u]);
    ret += dfs(u, r, ct.rig[u]);
    ret /= 2;
  } else {
    ret = (r - l);
  }
// cerr<<"dfs "<<l<<" "<<r<<" "<<u<<": "<<ret<<endl;
  return ret;
}
Mint run() {
cerr<<"[brute::run]"<<endl;
  Mint ans = 0;
  for (int q = 0; q < Q; ++q) if (O[q] == 1) {
    qs.assign(N + 2, Q);
    for (int qq = q + 1; qq < Q; ++qq) if (O[qq] == 2) {
      if (L[q] < X[qq] && X[qq] < R[q]) {
        chmin(qs[X[qq]], qq);
      }
    }
// cerr<<L[q]<<" "<<R[q]<<" "<<qs<<endl;
    ct.build(qs);
    ans += dfs(L[q], R[q], ct.rt);
  }
  return ans;
}
}  // brute


namespace slow {
Mint run() {
cerr<<"[slow::run]"<<endl;
  const Mint INV2 = Mint(2).inv();
  vector<Mint> invTwo(N + 1, 1);
  invTwo[0] = 1;
  for (int i = 1; i <= N; ++i) invTwo[i] = invTwo[i - 1] * INV2;
  
  vector<int> qs(N + 2, Q);
  for (int q = 0; q < Q; ++q) if (O[q] == 2) {
    chmin(qs[X[q]], q);
  }
  Mint ans = 0;
  vector<int> ds(N + 2, 0);
  vector<int> stack(N + 2);
  for (int q = 0; q < Q; ++q) if (O[q] == 1) {
    {
      int top = 0;
      stack[0] = -1;
      ds[L[q]] = 0;
      for (int x = L[q] + 1; x < R[q]; ++x) {
        if (q < qs[x] && qs[x] < Q) {
          for (; stack[top] >= qs[x]; --top) {}
          stack[++top] = qs[x];
        }
        ds[x] = top;
      }
    }
    {
      int top = 0;
      stack[0] = -1;
      ds[R[q] - 1] += 0;
      for (int x = R[q] - 1; x > L[q]; --x) {
        if (q < qs[x] && qs[x] < Q) {
          for (; stack[top] >= qs[x]; --top) {}
          stack[++top] = qs[x];
        }
        ds[x - 1] += top;
      }
    }
    for (int x = L[q]; x < R[q]; ++x) {
      ans += invTwo[ds[x]];
    }
  }
  return ans;
}
}  // sub3


int main() {
  for (; ~scanf("%d%d", &N, &Q); ) {
    O.resize(Q);
    L.assign(Q, 0);
    R.assign(Q, 0);
    X.assign(Q, 0);
    for (int q = 0; q < Q; ++q) {
      scanf("%d", &O[q]);
      if (O[q] == 1) {
        scanf("%d%d", &L[q], &R[q]);
      } else {
        scanf("%d", &X[q]);
      }
    }
    
    bool spe3 = true;
    for (int q = 0; q < Q; ++q) if (O[q] == 2) {
      for (int qq = q; qq < Q; ++qq) spe3 = spe3 && (O[qq] == 2);
      break;
    }
    
    Mint ans = slow::run();
    printf("%u\n", ans.x);
  }
  return 0;
}

详细

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 3812kb

input:

500 500
1 119 258
2 134
2 417
2 176
2 61
2 60
2 110
1 335 336
1 96 111
2 202
1 138 344
2 358
2 134
1 29 54
1 73 381
1 179 495
2 490
2 418
2 186
2 183
1 168 340
2 78
1 15 27
2 373
1 245 498
1 372 495
2 244
2 63
1 174 490
2 282
2 417
1 272 408
1 109 134
2 303
2 345
1 238 401
1 36 480
1 21 483
2 10
1 3...

output:

169902410

result:

wrong answer 1st lines differ - expected: '855279801', found: '169902410'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Time Limit Exceeded

Test #13:

score: 40
Accepted
time: 6587ms
memory: 5012kb

input:

50000 50000
1 24367 33007
1 14396 42256
1 6375 22327
1 7892 42501
1 10100 37998
1 6284 48524
1 7357 18164
1 16200 46424
1 18972 34131
1 16849 32591
1 1917 3018
1 19897 30272
1 45044 45753
1 18999 25448
1 5167 31033
1 6182 35335
1 7270 37270
1 12651 39965
1 28896 38022
1 13853 35426
1 35516 48244
1 1...

output:

733099543

result:

ok single line: '733099543'

Test #14:

score: 0
Accepted
time: 5378ms
memory: 4796kb

input:

49951 43686
1 21796 23464
1 29304 46959
1 5034 41719
1 7779 35334
1 27566 36486
1 20347 26165
1 12508 30387
1 18363 20335
1 8540 21417
1 5728 49086
1 46038 47603
1 10371 15910
1 27293 43572
1 18915 45279
1 7388 48342
1 6802 43746
1 4361 40049
1 41177 43375
1 23287 48354
1 37097 41733
1 2406 11638
1 ...

output:

792296531

result:

ok single line: '792296531'

Test #15:

score: -40
Time Limit Exceeded

input:

49914 43874
1 8935 40963
1 4425 44317
1 1769 45855
1 2436 40257
1 1778 47216
1 383 42149
1 5398 40732
1 1079 43346
1 6578 41660
1 9689 45985
1 6131 42681
1 8862 47431
1 3979 46189
1 6456 43485
1 2028 46574
1 3802 47787
1 6990 41659
1 9221 41204
1 2271 43554
1 8018 45280
1 9344 43917
1 6623 41152
1 7...

output:


result:


Subtask #4:

score: 0
Skipped

Dependency #1:

0%