結果
問題 | No.2574 Defect-free Rectangles |
ユーザー | Taiki0715 |
提出日時 | 2023-12-02 16:55:22 |
言語 | C++23 (gcc 12.3.0 + boost 1.83.0) |
結果 |
TLE
|
実行時間 | - |
コード長 | 6,499 bytes |
コンパイル時間 | 3,321 ms |
コンパイル使用メモリ | 251,596 KB |
実行使用メモリ | 21,120 KB |
最終ジャッジ日時 | 2024-09-26 20:53:09 |
合計ジャッジ時間 | 15,941 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 2 ms
5,376 KB |
testcase_03 | AC | 4 ms
5,376 KB |
testcase_04 | AC | 4 ms
5,376 KB |
testcase_05 | AC | 4 ms
5,376 KB |
testcase_06 | AC | 210 ms
9,344 KB |
testcase_07 | AC | 251 ms
9,472 KB |
testcase_08 | AC | 246 ms
9,472 KB |
testcase_09 | TLE | - |
testcase_10 | AC | 1,960 ms
21,120 KB |
testcase_11 | TLE | - |
testcase_12 | TLE | - |
testcase_13 | AC | 1,541 ms
20,992 KB |
testcase_14 | AC | 670 ms
12,160 KB |
testcase_15 | AC | 273 ms
8,448 KB |
testcase_16 | AC | 57 ms
5,888 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) static_cast<void>(0) #define debugg(...) static_cast<void>(0) template<typename T1,typename T2>ostream &operator<<(ostream &os,const pair<T1,T2>&p){os<<p.first<<' '<<p.second;return os;} #endif using ll=long long; using ull=unsigned long long; using P=pair<ll,ll>; template<typename T>using minque=priority_queue<T,vector<T>,greater<T>>; template<typename T>bool chmax(T &a,const T &b){return (a<b?(a=b,true):false);} template<typename T>bool chmin(T &a,const T &b){return (a>b?(a=b,true):false);} template<typename T1,typename T2>istream &operator>>(istream &is,pair<T1,T2>&p){is>>p.first>>p.second;return is;} template<typename T>istream &operator>>(istream &is,vector<T> &a){for(auto &i:a)is>>i;return is;} template<typename T1,typename T2>void operator++(pair<T1,T2>&a,int n){a.first++,a.second++;} template<typename T1,typename T2>void operator--(pair<T1,T2>&a,int n){a.first--,a.second--;} template<typename T>void operator++(vector<T>&a,int n){for(auto &i:a)i++;} template<typename T>void operator--(vector<T>&a,int n){for(auto &i:a)i--;} #define reps(i,a,n) for(int i=(a);i<(n);i++) #define rep(i,n) reps(i,0,n) #define all(x) x.begin(),x.end() #define pcnt(x) __builtin_popcount(x) ll myceil(ll a,ll b){return (a+b-1)/b;} namespace atcoder { template <class S, S (*op)(S, S), S (*e)(), class F, S (*mapping)(F, S), F (*composition)(F, F), F (*id)()> struct lazy_segtree { public: lazy_segtree() : lazy_segtree(0) {} explicit lazy_segtree(int n) : lazy_segtree(std::vector<S>(n, e())) {} explicit lazy_segtree(const std::vector<S>& v) : _n(int(v.size())) { size=4096; log=12; d = std::vector<S>(2 * size, e()); lz = std::vector<F>(size, id()); for (int i = 0; i < _n; i++) d[size + i] = v[i]; for (int i = size - 1; i >= 1; i--) { update(i); } } S prod(int r){ if(r==0)return e(); r+=size; push(1); for(int i=log;i>=1;i--){ if (((r >> i) << i) != r) push((r - 1) >> i); } S ret=e(); int l=size; while(l!=r){ if(l==1)ret=op(d[l],ret); if(r&1)ret=op(d[--r],ret); r>>=1; l>>=1; } return ret; } S all_prod() { return d[1]; } void apply(int p, F f) { assert(0 <= p && p < _n); p += size; for (int i = log; i >= 1; i--) push(p >> i); d[p] = mapping(f, d[p]); for (int i = 1; i <= log; i++) update(p >> i); } void apply(int l, int r, F f) { if (l == r) return; l += size; r += size; push(l>>log); for (int i = log; i >= 1; i--) { if (((r >> i) << i) != r) push((r - 1) >> i); } { int l2 = l, r2 = r; while (l < r) { if (l & 1) all_apply(l++, f); if (r & 1) all_apply(--r, f); l >>= 1; r >>= 1; } l = l2; r = r2; } for (int i = 1; i <= log; i++) { if (((l >> i) << i) != l) update(l >> i); if (((r >> i) << i) != r) update((r - 1) >> i); } } template <bool (*g)(S)> int max_right(int l) { return max_right(l, [](S x) { return g(x); }); } template <class G> int max_right(int l, G g) { assert(0 <= l && l <= _n); assert(g(e())); if (l == _n) return _n; l += size; for (int i = log; i >= 1; i--) push(l >> i); S sm = e(); do { while (l % 2 == 0) l >>= 1; if (!g(op(sm, d[l]))) { while (l < size) { push(l); l = (2 * l); if (g(op(sm, d[l]))) { sm = op(sm, d[l]); l++; } } return l - size; } sm = op(sm, d[l]); l++; } while ((l & -l) != l); return _n; } template <bool (*g)(S)> int min_left(int r) { return min_left(r, [](S x) { return g(x); }); } template <class G> int min_left(int r, G g) { assert(0 <= r && r <= _n); assert(g(e())); if (r == 0) return 0; r += size; for (int i = log; i >= 1; i--) push((r - 1) >> i); S sm = e(); do { r--; while (r > 1 && (r % 2)) r >>= 1; if (!g(op(d[r], sm))) { while (r < size) { push(r); r = (2 * r + 1); if (g(op(d[r], sm))) { sm = op(d[r], sm); r--; } } return r + 1 - size; } sm = op(d[r], sm); } while ((r & -r) != r); return 0; } private: int _n, size, log; std::vector<S> d; std::vector<F> lz; void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); } void all_apply(int k, F f) { d[k] = mapping(f, d[k]); if (k < size) lz[k] = composition(f, lz[k]); } void push(int k) { all_apply(2 * k, lz[k]); all_apply(2 * k + 1, lz[k]); lz[k] = id(); } }; } // namespace atcoder struct S{ int sz; int sum; }; S op(S x,S y){return {x.sz+y.sz,x.sum+y.sum};} S e(){return {0,0};} S mapping(int f,S x){ if(f!=-10)x.sum=f*x.sz; return x; } int composition(int f,int g){ if(f!=-10)return f; return g; } int id(){return -10;} int read_int() { int ret = 0; char ch = getchar_unlocked(); while (isspace(ch)) { ch = getchar_unlocked(); } for (; isdigit(ch); ch = getchar_unlocked()) ret = (ret * 10) + (ch - '0'); ungetc(ch, stdin); return ret; } short a[3000][3000]; int main(){ int h,w; h=read_int(),w=read_int(); ll ans=0; int n; n=read_int(); int x,y; rep(i,h)rep(j,w)a[i][j]=-1; rep(i,n){ x=read_int(),y=read_int(); a[x-1][y-1]=0; } for(int i=h-1;i>=0;--i)rep(j,w)if(a[i][j]==-1){ if(i==h-1)a[i][j]=1; else a[i][j]=a[i+1][j]+1; } vector<S>dat(4096,{1,0}); atcoder::lazy_segtree<S,op,e,int,mapping,composition,id>seg(dat); rep(i,h){ seg.apply(0,h,-1); rep(j,w){ ans+=j*a[i][j]-seg.prod(a[i][j]).sum; seg.apply(a[i][j],4096,j); } } cout<<ans<<endl; }