結果
問題 | No.1008 Bench Craftsman |
ユーザー | koi_kotya |
提出日時 | 2020-03-06 23:00:38 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 3,242 bytes |
コンパイル時間 | 1,919 ms |
コンパイル使用メモリ | 178,316 KB |
実行使用メモリ | 26,024 KB |
最終ジャッジ日時 | 2024-10-14 09:29:24 |
合計ジャッジ時間 | 5,761 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
13,636 KB |
testcase_01 | AC | 2 ms
6,820 KB |
testcase_02 | AC | 2 ms
6,820 KB |
testcase_03 | AC | 2 ms
6,820 KB |
testcase_04 | WA | - |
testcase_05 | TLE | - |
testcase_06 | -- | - |
testcase_07 | -- | - |
testcase_08 | -- | - |
testcase_09 | -- | - |
testcase_10 | -- | - |
testcase_11 | -- | - |
testcase_12 | -- | - |
testcase_13 | -- | - |
testcase_14 | -- | - |
testcase_15 | -- | - |
testcase_16 | -- | - |
testcase_17 | -- | - |
testcase_18 | -- | - |
testcase_19 | -- | - |
testcase_20 | -- | - |
testcase_21 | -- | - |
testcase_22 | -- | - |
testcase_23 | -- | - |
testcase_24 | -- | - |
testcase_25 | -- | - |
testcase_26 | -- | - |
testcase_27 | -- | - |
testcase_28 | -- | - |
testcase_29 | -- | - |
ソースコード
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int,int> P; #define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0) #define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0) template<typename T1,typename T2>ostream& operator<<(ostream& os,const pair<T1,T2>& a) {os << "(" << a.first << ", " << a.second << ")";return os;} struct LazySegmentTree { private: int n; vector<ll> node,lazy; public: LazySegmentTree(vector<ll> v) { int sz = v.size(); n = 1; while (n < sz) n *= 2; node.resize(2*n-1); lazy.resize(2*n-1,0); for (int i = 0;i < sz;++i) node[i+n-1] = v[i]; for (int i = n-2;i >= 0;--i) node[i] = node[i*2+1]+node[i*2+2]; } void eval(int k,int l,int r) { if (lazy[k] != 0) { node[k] += lazy[k]; if (r-l > 1) { lazy[2*k+1] += lazy[k]/2; lazy[2*k+2] += lazy[k]/2; } lazy[k] = 0; } } void add(int a,int b,ll x,int k = 0,int l = 0,int r = -1) { if (r < 0) r = n; eval(k,l,r); if (b <= l || r <= a) return; if (a <= l && r <= b) { lazy[k] += (r-l)*x; eval(k,l,r); } else { add(a,b,x,2*k+1,l,(l+r)/2); add(a,b,x,2*k+2,(l+r)/2,r); node[k] = node[2*k+1]+node[2*k+2]; } } ll getsum(int a,int b,int k = 0,int l = 0,int r = -1) { if (r < 0) r = n; if (b <= l || r <= a) return 0; eval(k,l,r); if (a <= l && r <= b) return node[k]; ll vl = getsum(a,b,k*2+1,l,(l+r)/2); ll vr = getsum(a,b,2*k+2,(l+r)/2,r); return vl+vr; } }; int main() { int n,m; cin >> n >> m; vector<ll> a(n),w(m),sum(n,0); vector<int> x(m); for (int i = 0;i < n;++i) scanf("%lld",&a[i]); for (int i = 0;i < m;++i) scanf("%d%lld",&x[i],&w[i]),x[i]--; for (int i = 0;i < m;++i) sum[x[i]] += w[i]; for (int i = 0;i < n;++i) if (a[i] < sum[i]) { cout << -1 << endl; return 0; } ll s = 0; for (int i = 0;i < m;++i) s += w[i]; bool f = true; for (int i = 0;i < n;++i) if (a[i] < s) {f = false;break;} if (f) { cout << 0 << endl; return 0; } ll mn = 0,mx = 1e9; while (mx-mn > 1) { int mid = (mn+mx)/2; LazySegmentTree seg1(vector<ll>(n,0)),seg2(vector<ll>(n,0)),seg3(vector<ll>(n,0)); for (int i = 0;i < m;++i) { int c = w[i]/mid; seg1.add(x[i]-c,x[i]+c+1,w[i]); seg2.add(x[i]+1,x[i]+1+c,mid); seg2.add(x[i]+1+c,x[i]+2+c,-(ll)c*mid); seg3.add(x[i]-c,x[i],mid); seg3.add(x[i]-c-1,x[i]-c,-(ll)c*mid); } bool ok = true; for (int i = 0;i < n;++i) if (seg1.getsum(i,i+1)-seg2.getsum(0,i+1)-seg3.getsum(i,n) > a[i]) { ok = false; break; } (ok ? mx : mn) = mid; } cout << mx << endl; }