結果
問題 | No.3122 Median of Medians of Division |
ユーザー |
![]() |
提出日時 | 2025-04-19 01:08:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 325 ms / 2,000 ms |
コード長 | 1,224 bytes |
コンパイル時間 | 4,327 ms |
コンパイル使用メモリ | 253,584 KB |
実行使用メモリ | 12,256 KB |
最終ジャッジ日時 | 2025-04-19 01:08:54 |
合計ジャッジ時間 | 17,845 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 40 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:25:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 25 | rep(i,n)scanf("%d",&a[i]); | ~~~~~^~~~~~~~~~~~ main.cpp:28:22: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 28 | scanf("%d %d %d",&ts[i],&ls[i],&rs[i]); | ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ソースコード
#include <stdio.h> #include <atcoder/all> #include <bits/stdc++.h> using namespace std; using namespace atcoder; using mint = modint998244353; #define rep(i,n) for (int i = 0; i < (n); ++i) #define Inf32 1000000001 #define Inf64 4000000000000000001LL using P = pair<int,int>; P op(P a,P b){ if(a<b)swap(a,b); a.second = max(a.second,b.first); return a; } P e(){ return P(-Inf32,-Inf32); } int main(){ int n,q; cin>>n>>q; vector<int> a(n); rep(i,n)scanf("%d",&a[i]); vector<int> ts(q),ls(q),rs(q); rep(i,q){ scanf("%d %d %d",&ts[i],&ls[i],&rs[i]); ls[i]--; } segtree<P,op,e> seg(n-1); rep(i,n-1){ seg.set(i,P(min(a[i],a[i+1]),-Inf32)); } rep(_,q){ int t = ts[_]; int l = ls[_],r = rs[_]; if(t==1){ a[l] = r; for(int j=l-1;j<=l;j++){ if(j<0 || j==n-1)continue; seg.set(j,P(min(a[j],a[j+1]),-Inf32)); } } else{ int ans = Inf32; ans = min(ans,seg.prod(l,r-1).second); if(r-l==1)ans = a[l]; else{ ans = max(ans,min(a[l],a[l+1])); ans = max(ans,min(a[r-1],a[r-2])); ans = max(ans,min(a[l],a[r-1])); ans = max(ans,min(a[l],seg.prod(l+1,r-1).first)); ans = max(ans,min(a[r-1],seg.prod(l,r-2).first)); } cout<<ans<<endl; } } return 0; }