Submission #74315503


Source Code Expand

#include<bits/extc++.h>

#pragma GCC optimize("O3","unroll-loops")
#pragma GCC target("avx,avx2")

#include<iostream>
#include<queue>
#include<vector>
#include<cmath>
#include<map>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

#define coutc "\033[48;5;196m\033[38;5;15m"
#define endc "\033[0m"
#define M(_1, _2, _3, _4, NAME, ...) NAME
#define rep(...) \
  M(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rep4(_, x, n, s) \
  for (int _ = x; (s < 0) ? _ > n : _ < n; _ += s)
#define rep3(_, x, n) rep4(_, x, n, (x < n ? 1 : -1))
#define rep2(_, n) rep3(_, 0, n)
#define rep1(n) rep2(i, n)

#define FOR(i, a, b) for (int i=a; i<b; i++)
#define F0R(i, a) for (int i=0; i<a; i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) a*b/gcd(a,b)

#define mp make_pair
// #define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define endl "\n"

// #define cin fin
// #define cout fout

// ifstream fin("word.in");
// ofstream fout("word.out");

const int inf = INT_MAX;
const int MOD = 998244353;
double PI = 4*atan(1);

#ifdef DEBUG
string to_string(char c) { return string({c}); }
// 7
template<class... Ts>
ostream& operator<<(ostream& o, tuple<Ts...> t) {
  string s = "(";
  apply([&](auto&&... r) {
    ((s += to_string(r) + ", "), ...); }, t);
  return o << s.substr(0, len(s) - 2) + ")";
}
// 3
ostream& operator<<(ostream &o, pair<auto, auto> p) {
  return o << "(" << p.fi << ", " << p.se << ")";
}
// 7
template<class C, class T = typename C::value_type,
typename std::enable_if<!std::is_same<C, std::string>
::value>::type* = nullptr>
ostream& operator<<(ostream &o, C c) {
  for (auto e : c) o << setw(7) << right << e;
  return o << endc << endl << coutc;
}
// 7
void debug(const auto &e, const auto &... r) {
  cout << coutc << e;
  ((cout << " " << r), ..., (cout << endc << endl));
}
#else
#define debug(...)
#endif

map<string,int> mon;
map<int,string> inp;

vector<ll> seg, lz;

void push(int p, int l, int r) {
    if (lz[p] == 1) return;
    seg[p] = seg[p] * lz[p] % MOD;
    if (l != r) {
        lz[p << 1] = lz[p << 1] * lz[p] % MOD;
        lz[p << 1 | 1] = lz[p << 1 | 1] * lz[p] % MOD;
    }
    lz[p] = 1;
}

void pull(int p, int l, int r) {
    int m = (l + r) >> 1;
    push(p << 1, l, m);
    push(p << 1 | 1, m + 1, r);
    seg[p] = (seg[p << 1] + seg[p << 1 | 1]) % MOD;
}

void mul(int p, int l, int r, int ql, int qr, ll v) {
    push(p, l, r);
    if (ql > r || qr < l) return;
    if (ql <= l && r <= qr) {
        lz[p] = lz[p] * v % MOD;
        push(p, l, r);
        return;
    }
    int m = (l + r) >> 1;
    mul(p << 1, l, m, ql, qr, v);
    mul(p << 1 | 1, m + 1, r, ql, qr, v);
    pull(p, l, r);
}

void add(int p, int l, int r, int x, ll v) {
    push(p, l, r);
    if (l == r) {
        seg[p] += v;
        if (seg[p] >= MOD) seg[p] -= MOD;
        return;
    }
    int m = (l + r) >> 1;
    if (x <= m) add(p << 1, l, m, x, v);
    else add(p << 1 | 1, m + 1, r, x, v);
    pull(p, l, r);
}

ll qry(int p, int l, int r, int ql, int qr) {
    if (ql > r || qr < l) return 0;
    push(p, l, r);
    if (ql <= l && r <= qr) return seg[p];
    int m = (l + r) >> 1;
    return (qry(p << 1, l, m, ql, qr) + qry(p << 1 | 1, m + 1, r, ql, qr)) % MOD;
}

void _main(int tc) {
    int N, M;
    cin >> N >> M;

    vector<pi> e(M);
    int i = 0;
    while (i < M) {
        int x, y;
        cin >> x >> y;
        e[i] = {x, y - 1};
        i++;
    }

    sort(e.begin(), e.end());

    seg.assign(4 * N + 5, 0);
    lz.assign(4 * N + 5, 1);
    add(1, 0, N - 1, 0, 1);

    i = 0;
    while (i < M) {
        int l = e[i].f;
        int r = e[i].s;

        ll x = qry(1, 0, N - 1, l - 1, r - 1);
        mul(1, 0, N - 1, r, N - 1, 2);
        add(1, 0, N - 1, r, x);
        i++;
    }

    cout << qry(1, 0, N - 1, N - 1, N - 1) << endl;
}
// 5
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  _main(0), exit(0);
  int tc; cin >> tc; rep(i, tc) _main(i + 1);
}

Submission Info

Submission Time
Task F - Strongly Connected 2
User zaahir
Language C++23 (GCC 15.2.0)
Score 525
Code Size 4479 Byte
Status AC
Exec Time 170 ms
Memory 17488 KiB

Compile Error

./Main.cpp: In function 'void _main(int)':
./Main.cpp:146:16: warning: unused parameter 'tc' [-Wunused-parameter]
  146 | void _main(int tc) {
      |            ~~~~^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 525 / 525
Status
AC × 2
AC × 24
Set Name Test Cases
Sample sample_01.txt, sample_02.txt
All min.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, sample_01.txt, sample_02.txt
Case Name Status Exec Time Memory
min.txt AC 1 ms 3668 KiB
random_01.txt AC 166 ms 17488 KiB
random_02.txt AC 10 ms 9564 KiB
random_03.txt AC 164 ms 17400 KiB
random_04.txt AC 24 ms 6096 KiB
random_05.txt AC 165 ms 17432 KiB
random_06.txt AC 25 ms 4188 KiB
random_07.txt AC 165 ms 17400 KiB
random_08.txt AC 20 ms 15904 KiB
random_09.txt AC 163 ms 17252 KiB
random_10.txt AC 108 ms 7436 KiB
random_11.txt AC 165 ms 17448 KiB
random_12.txt AC 8 ms 15468 KiB
random_13.txt AC 164 ms 17372 KiB
random_14.txt AC 118 ms 6876 KiB
random_15.txt AC 170 ms 17396 KiB
random_16.txt AC 10 ms 13344 KiB
random_17.txt AC 61 ms 10716 KiB
random_18.txt AC 86 ms 5724 KiB
random_19.txt AC 31 ms 12652 KiB
random_20.txt AC 102 ms 17372 KiB
random_21.txt AC 5 ms 15904 KiB
sample_01.txt AC 1 ms 3480 KiB
sample_02.txt AC 1 ms 3608 KiB