結果
問題 | No.255 Splarrraaay スプラーレェーーイ |
ユーザー | omochanal |
提出日時 | 2018-11-20 23:40:48 |
言語 | C++11 (gcc 11.4.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 4,676 bytes |
コンパイル時間 | 1,900 ms |
コンパイル使用メモリ | 169,600 KB |
実行使用メモリ | 5,376 KB |
最終ジャッジ日時 | 2024-06-06 21:26:14 |
合計ジャッジ時間 | 2,845 ms |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | WA | - |
testcase_01 | WA | - |
testcase_02 | WA | - |
testcase_03 | WA | - |
testcase_04 | AC | 2 ms
5,376 KB |
testcase_05 | WA | - |
testcase_06 | WA | - |
testcase_07 | WA | - |
testcase_08 | WA | - |
testcase_09 | WA | - |
ソースコード
#include <bits/stdc++.h> #define ADD(a, b) a = (a + ll(b)) % mod #define MUL(a, b) a = (a * ll(b)) % mod #define MAX(a, b) a = max(a, b) #define MIN(a, b) a = min(a, b) #define rep(i, a, b) for(int i = int(a); i < int(b); i++) #define rer(i, a, b) for(int i = int(a) - 1; i >= int(b); i--) #define all(a) (a).begin(), (a).end() #define sz(v) (int)(v).size() #define pb push_back #define sec second #define fst first #define debug(fmt, ...) Debug(__LINE__, ":", fmt, ##__VA_ARGS__) using namespace std; typedef long long ll; typedef unsigned long long ull; typedef pair<int, int> pi; typedef pair<ll, ll> pl; typedef pair<int, pi> ppi; typedef vector<int> vi; typedef vector<ll> vl; typedef vector<vl> mat; typedef complex<double> comp; void Debug() {cout << '\n'; } template<class FIRST, class... REST>void Debug(FIRST arg, REST... rest){ cout<<arg<<" ";Debug(rest...);} template<class T>ostream& operator<<(ostream& out,const vector<T>& v) { out<<"[";if(!v.empty()){rep(i,0,sz(v)-1)out<<v[i]<<", ";out<<v.back();}out<<"]";return out;} template<class S, class T>ostream& operator<<(ostream& out,const pair<S, T>& v){ out<<"("<<v.first<<", "<<v.second<<")";return out;} const int MAX_N = 300010; const int MAX_V = 100010; const double eps = 1e-6; const ll mod = 1000000007; const int inf = 1 << 30; const ll linf = 1LL << 60; const double PI = 3.14159265358979323846; /////////////////////////////////////////////////////////////////////////////////////////////////// vector<ll> vx; struct segtree { // this is piece of shit. use BIT int n; vl sum, lazy, zero; void init(int mx) { n = 1; while(n < mx) n *= 2; sum = vl(n * 2, 0); lazy = vl(n * 2, 0); zero = vl(n * 2, 0); } segtree(int mx = 0) { init(mx); } inline void lazy_eval(int k, int l, int r) { int m = (l + r) / 2; if(lazy[k]) { sum[k * 2 + 1] += (vx[m] - vx[l]) * lazy[k];//if range_min, erase (m - l) lazy[k * 2 + 1] += lazy[k]; sum[k * 2 + 2] += (vx[r] - vx[m]) * lazy[k];//here too lazy[k * 2 + 2] += lazy[k]; lazy[k] = 0; } } void app(int a, int b, ll s, int k, int l, int r) { if(b <= l || r <= a) return; if(a <= l && r <= b) { sum[k] += (vx[r] - vx[l]) * s; //here too lazy[k] = lazy[k] + s; } else { zero[k] = 1; lazy_eval(k, l, r); app(a, b, s, k * 2 + 1, l, (l + r) / 2); app(a, b, s, k * 2 + 2, (l + r) / 2, r); sum[k] = sum[k * 2 + 1] + sum[k * 2 + 2]; } } void cln(int a, int b, int k, int l, int r) { if(b <= l || r <= a) return; if(a <= l && r <= b) { if(zero[k]) { cln(a, b, k * 2 + 1, l, (l + r) / 2); cln(a, b, k * 2 + 2, (l + r) / 2, r); } zero[k] = 0; sum[k] = 0; lazy[k] = 0; } else { lazy_eval(k, l, r); cln(a, b, k * 2 + 1, l, (l + r) / 2); cln(a, b, k * 2 + 2, (l + r) / 2, r); sum[k] = sum[k * 2 + 1] + sum[k * 2 + 2]; } } ll ga(int a, int b, int k, int l, int r) { if(b <= l || r <= a) return ll(); if(a <= l && r <= b) return sum[k]; else { lazy_eval(k, l, r); ll lv = ga(a, b, k * 2 + 1, l, (l + r) / 2); ll rv = ga(a, b, k * 2 + 2, (l + r) / 2, r); return lv + rv; } } void show() { vector<ll> tmp; rep(i, 0, n) tmp.push_back(get(i, i + 1)); debug(tmp); } ll get(int a, int b) { return ga(a, b, 0, 0, n); } //[a, b) void update(int a, int b, ll s) { app(a, b, s, 0, 0, n); } //[a, b) void clean(int a, int b) { cln(a, b, 0, 0, n); } }; int fd(ll a) { return lower_bound(all(vx), a) - vx.begin(); } int N, Q; ll X[MAX_N], L[MAX_N], R[MAX_N]; ll ans[MAX_N]; segtree seg[5]; void solve() { cin >> N >> Q; rep(i, 0, Q) { cin >> X[i] >> L[i] >> R[i]; R[i]++; vx.pb(L[i]); vx.pb(R[i]); } sort(all(vx)); vx.erase(unique(all(vx)), vx.end()); rep(i, 0, 5) seg[i].init(sz(vx)); // debug(vx); rep(i, 0, Q) { int l = fd(L[i]), r = fd(R[i]); // debug(l, r, L[i], R[i]); if(X[i] == 0) { vector<ll> vec(5); rep(j, 0, 5) vec[j] = seg[j].get(l, r); int at = -1; ll mv = -linf; rep(j, 0, 5) { if(mv < vec[j]) { at = j; mv = vec[j]; } else if(mv == vec[j]) at = -1; } if(at != -1) ans[at] += vec[at]; } else { rep(j, 0, 5) { if(j == X[i] - 1) seg[j].update(l, r, 1); else seg[j].clean(l, r); } } } rep(j, 0, 5) { ans[j] += seg[j].get(0, sz(vx)); cout << ans[j] << (j == 4 ? '\n' : ' '); } } int main() { #ifndef LOCAL ios::sync_with_stdio(false); cin.tie(0); #endif cout << fixed; cout.precision(20); srand((unsigned int)time(NULL)); #ifdef LOCAL //freopen("in.txt", "wt", stdout); //for tester freopen("in.txt", "rt", stdin); #endif solve(); #ifdef LOCAL cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"; #endif return 0; }