Submission #1061482

#TimeUsernameProblemLanguageResultExecution timeMemory
1061482ewirlanDigital Circuit (IOI22_circuit)C++17
100 / 100
762 ms28520 KiB
// #ifndef __SIZEOF_INT128__ #define __SIZEOF_INT128__ #endif #pragma GCC optimize("Ofast") #include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; using namespace chrono; using namespace __gnu_pbds; template <typename T> using oset = tree<T, null_type, less_equal<T>, rb_tree_tag, tree_order_statistics_node_update>; #define rep(i, p, k) for(int i(p); i < (k); ++i) #define per(i, p, k) for(int i(p); i > (k); --i) #define sz(x) (int)(x).size() #define sc static_cast typedef long long ll; typedef long double ld; typedef unsigned int uint; typedef unsigned long long ull; typedef __int128_t lll; //#define int ll template <typename T = int> using par = std::pair <T, T>; #define fi first #define se second #define test int _number_of_tests(in()); while(_number_of_tests--) #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() #define pb emplace_back struct Timer { string name{""}; time_point<high_resolution_clock> end, start{high_resolution_clock::now()}; duration<float, std::milli> dur; Timer() = default; Timer(string nm): name(nm) {} ~Timer() { end = high_resolution_clock::now(); dur= end - start; cout << "@" << name << "> " << dur.count() << " ms" << '\n'; } }; template <typename T = int> inline T in() { static T x; std::cin >> x; return x; } std::string yn(bool b) { if(b) return "YES\n"; else return "NO\n"; } template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par); template <typename T> std::ostream& operator<< (std::ostream& out, const std::vector <T>& wek) { for(const auto& i : wek)out << i << ' '; return out; } template <typename F, typename S> std::ostream& operator<<(std::ostream& out, const std::pair <F, S>& par) { out << '{'<<par.first<<", "<<par.second<<"}"; return out; } #define show(x) cerr << #x << " = " << x << '\n'; #include "circuit.h" constexpr int maxn = 1e5 + 3, mod = 1e9 + 2022, pol = 1<<17; ll mm(ll a, ll b){return (a*b)%mod;} ll dm(ll a, ll b){return (a+b)%mod;} ll om(ll a, ll b){return (mod+a-b)%mod;} vector <int> syn[2*maxn]; int a[maxn*2], z[maxn]; int N, M; int la(int w) { a[w] = max(1, sz(syn[w])); for(auto i: syn[w])a[w] = mm(a[w], la(i)); return a[w]; } void lz(int w, ll g) { if(w >= N){ z[w-N] = g; return; } int ss(sz(syn[w])); vector <ll> p(ss+1), s(ss+1); p.front() = s.back() = 1; rep(i, 0, ss)p[i+1] = mm(a[syn[w][i]], p[i]); per(i, ss-1, 0)s[i] = mm(a[syn[w][i]], s[i+1]); rep(i, 0, ss)lz(syn[w][i], mm(g, mm(p[i], s[i+1]))); } constexpr int tres = pol*2+3; int tre[tres]; bool tre2[tres]; int ful[tres]; void init(int n, int m, vector <int> p, vector <int> c) { N = n; M = m; rep(i, 1, n+m)syn[p[i]].pb(i); la(0); lz(0, 1); rep(i, 0, m){ ful[pol+i] = z[i]; tre[pol+i] = z[i]*c[i]; } per(i, pol-1, 0){ ful[i] = dm(ful[2*i], ful[2*i+1]); tre[i] = dm(tre[2*i], tre[2*i+1]); } } void flip(int i){ tre[i] = om(ful[i], tre[i]); tre2[i] = !tre2[i]; } void pyt(int a, int b, int p, int k, int w) { // cerr << p << " - " << k << ": " << ful[w] << ' ' << tre[w] << '\n'; if(a > k || p > b)return; if(a <= p && k <= b){ // cerr << "switch " << p << ' ' << k << " (" << a << ',' << b << ')' << '\n'; flip(w); return; } if(tre2[w]){ tre2[w] = 0; flip(w*2); flip(w*2+1); } pyt(a, b, p, (p+k)/2, w*2); pyt(a, b, (p+k)/2+1, k, w*2+1); tre[w] = dm(tre[w*2], tre[w*2+1]); } int count_ways(int a, int b) { pyt(a-N, b-N, 0, pol-1, 1); return tre[1]; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...