QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#282099 | #7872. 崩坏天际线 | hos_lyric# | 0 | 1ms | 3884kb | C++14 | 5.8kb | 2023-12-11 13:26:36 | 2024-07-04 03:12:18 |
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
int main() {
for (; ~scanf("%d%d", &N, &Q); ) {
O.resize(Q);
L.assign(N, 0);
R.assign(N, 0);
X.assign(N, 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]);
}
}
const Mint ans = brute::run();
printf("%u\n", ans.x);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 10
Accepted
time: 1ms
memory: 3884kb
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:
855279801
result:
ok single line: '855279801'
Test #2:
score: 0
Accepted
time: 1ms
memory: 3884kb
input:
495 466 1 35 393 2 236 1 4 335 2 455 1 36 470 1 23 61 2 195 2 109 2 451 1 282 491 2 238 2 117 2 468 1 2 60 1 439 487 2 238 1 209 294 2 321 2 309 1 113 183 2 409 2 87 2 130 2 124 2 176 2 448 2 379 1 181 446 2 146 2 450 1 171 423 2 355 2 332 1 123 387 1 151 269 1 17 417 2 122 1 324 494 1 265 439 2 225...
output:
294468977
result:
ok single line: '294468977'
Test #3:
score: -10
Runtime Error
input:
441 467 2 180 1 51 344 2 180 1 16 345 1 39 419 1 64 432 2 176 1 35 372 2 426 1 8 415 1 1 439 1 17 430 2 433 1 89 369 1 83 353 2 292 1 1 421 1 63 430 1 33 345 1 69 421 1 49 373 1 77 343 1 24 393 1 90 375 1 8 425 2 322 2 61 2 112 2 209 1 39 406 1 12 426 1 29 430 1 50 374 1 47 394 1 9 387 2 234 1 19 35...
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Time Limit Exceeded
Test #13:
score: 0
Time Limit Exceeded
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:
result:
Subtask #4:
score: 0
Skipped
Dependency #1:
0%