結果
問題 | No.880 Yet Another Segment Tree Problem |
ユーザー | HIR180 |
提出日時 | 2019-09-10 21:51:52 |
言語 | C++11 (gcc 11.4.0) |
結果 |
AC
|
実行時間 | 699 ms / 5,000 ms |
コード長 | 3,195 bytes |
コンパイル時間 | 1,598 ms |
コンパイル使用メモリ | 179,580 KB |
実行使用メモリ | 10,240 KB |
最終ジャッジ日時 | 2024-09-22 19:38:36 |
合計ジャッジ時間 | 11,313 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge5 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 3 ms
5,376 KB |
testcase_02 | AC | 3 ms
5,376 KB |
testcase_03 | AC | 3 ms
5,376 KB |
testcase_04 | AC | 3 ms
5,376 KB |
testcase_05 | AC | 3 ms
5,376 KB |
testcase_06 | AC | 3 ms
5,376 KB |
testcase_07 | AC | 3 ms
5,376 KB |
testcase_08 | AC | 4 ms
5,376 KB |
testcase_09 | AC | 4 ms
5,376 KB |
testcase_10 | AC | 3 ms
5,376 KB |
testcase_11 | AC | 453 ms
8,576 KB |
testcase_12 | AC | 446 ms
8,960 KB |
testcase_13 | AC | 312 ms
8,064 KB |
testcase_14 | AC | 439 ms
9,600 KB |
testcase_15 | AC | 474 ms
9,728 KB |
testcase_16 | AC | 503 ms
9,600 KB |
testcase_17 | AC | 699 ms
10,240 KB |
testcase_18 | AC | 683 ms
10,240 KB |
testcase_19 | AC | 138 ms
8,960 KB |
testcase_20 | AC | 137 ms
9,216 KB |
testcase_21 | AC | 140 ms
8,704 KB |
testcase_22 | AC | 138 ms
9,088 KB |
testcase_23 | AC | 137 ms
8,960 KB |
testcase_24 | AC | 131 ms
9,472 KB |
testcase_25 | AC | 136 ms
9,344 KB |
testcase_26 | AC | 128 ms
9,088 KB |
testcase_27 | AC | 135 ms
9,472 KB |
testcase_28 | AC | 133 ms
9,216 KB |
testcase_29 | AC | 425 ms
9,728 KB |
testcase_30 | AC | 456 ms
9,472 KB |
testcase_31 | AC | 497 ms
9,856 KB |
testcase_32 | AC | 215 ms
8,448 KB |
testcase_33 | AC | 118 ms
7,936 KB |
testcase_34 | AC | 122 ms
8,192 KB |
testcase_35 | AC | 112 ms
8,192 KB |
testcase_36 | AC | 116 ms
8,064 KB |
testcase_37 | AC | 121 ms
8,448 KB |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:106:14: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 106 | scanf("%d%d",&n,&q); | ~~~~~^~~~~~~~~~~~~~ main.cpp:108:28: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 108 | ll a; scanf("%lld",&a); | ~~~~~^~~~~~~~~~~ main.cpp:113:40: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 113 | int ty,L,R; ll x; scanf("%d%d%d",&ty,&L,&R); | ~~~~~^~~~~~~~~~~~~~~~~~~~ main.cpp:114:34: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 114 | if(ty <= 2) scanf("%lld",&x); | ~~~~~^~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> #include <ext/pb_ds/assoc_container.hpp> #include <ext/pb_ds/tree_policy.hpp> using namespace std; typedef long long ll; typedef pair<int,int> P; typedef pair<int,P> P1; typedef pair<P,P> P2; #define pu push #define pb push_back #define mp make_pair #define eps 1e-7 #define INF 1500000000 #define mod 998244353 #define fi first #define sc second #define rep(i,x) for(int i=0;i<x;i++) #define repn(i,x) for(int i=1;i<=x;i++) #define SORT(x) sort(x.begin(),x.end()) #define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end()) #define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) #define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) ll gcdd(ll a,ll b){ if(a < b) swap(a,b); if(b == 0) return a; return gcdd(b,a%b); } ll makeL(ll a,ll b){ if(a == 0) return b; if(b == 0) return a; if(a >= INF || b >= INF) return INF; return min((ll)(INF),a*b/gcdd(a,b)); } ll L[1<<18],mx[1<<18],sum[1<<18]; ll upd[1<<18]; void push(int k,ll val){ L[k*2+1] = L[k*2+2] = mx[k*2+1] = mx[k*2+2] = upd[k*2+1] = upd[k*2+2] = upd[k]; sum[k*2+1] = sum[k*2+2] = val * upd[k]; upd[k] = 0; } void update(int x,ll v){ x += (1<<17)-1; L[x] = sum[x] = mx[x] = v; while(x){ x = (x-1)/2; L[x] = makeL(L[x*2+1],L[x*2+2]); sum[x] = sum[x*2+1]+sum[x*2+2]; mx[x] = max(mx[x*2+1],mx[x*2+2]); } } void set_val(int a,int b,int k,int l,int r,ll x){ if(r<a || b<l) return; if(a<=l && r<=b){ L[k] = x; sum[k] = x * (r-l+1); mx[k] = x; upd[k] = x; return; } if(upd[k]) push(k,(r-l+1)/2); set_val(a,b,k*2+1,l,(l+r)/2,x); set_val(a,b,k*2+2,(l+r)/2+1,r,x); L[k] = makeL(L[k*2+1],L[k*2+2]); sum[k] = sum[k*2+1]+sum[k*2+2]; mx[k] = max(mx[k*2+1],mx[k*2+2]); } void gcd_val(int a,int b,int k,int l,int r,ll x){ if(r<a || b<l || (L[k]<=x && x%L[k]==0)) return; if(a<=l && r<=b && L[k]*(r-l+1) == sum[k]){ L[k] = gcdd(x,L[k]); sum[k] = L[k] * (r-l+1); upd[k] = L[k]; mx[k] = L[k]; return; } if(upd[k]) push(k,(r-l+1)/2); gcd_val(a,b,k*2+1,l,(l+r)/2,x); gcd_val(a,b,k*2+2,(l+r)/2+1,r,x); //assume time complexity is log^2 if(a<=l && r<=b) { if(L[k] < INF) L[k] = gcdd(L[k],x); else L[k] = makeL(L[k*2+1],L[k*2+2]); } else L[k] = makeL(L[k*2+1],L[k*2+2]); sum[k] = sum[k*2+1]+sum[k*2+2]; mx[k] = max(mx[k*2+1],mx[k*2+2]); } ll calc_max(int a,int b,int k,int l,int r){ if(r<a || b<l) return 0; if(a<=l && r<=b){ return mx[k]; } if(upd[k]) push(k,(r-l+1)/2); return max(calc_max(a,b,k*2+1,l,(l+r)/2),calc_max(a,b,k*2+2,(l+r)/2+1,r)); } ll calc_sum(int a,int b,int k,int l,int r){ if(r<a || b<l) return 0; if(a<=l && r<=b){ return sum[k]; } if(upd[k]) push(k,(r-l+1)/2); return (calc_sum(a,b,k*2+1,l,(l+r)/2)+calc_sum(a,b,k*2+2,(l+r)/2+1,r)); } int main(){ int n,q; scanf("%d%d",&n,&q); repn(i,n){ ll a; scanf("%lld",&a); update(i,a); } rep(i,q){ int ty,L,R; ll x; scanf("%d%d%d",&ty,&L,&R); if(ty <= 2) scanf("%lld",&x); if(ty == 1){ set_val(L,R,0,0,(1<<17)-1,x); } else if(ty == 2){ gcd_val(L,R,0,0,(1<<17)-1,x); } else if(ty == 3){ printf("%lld\n",calc_max(L,R,0,0,(1<<17)-1)); } else{ printf("%lld\n",calc_sum(L,R,0,0,(1<<17)-1)); } } return 0; }