結果

問題 No.865 24時間降水量
ユーザー LayCurseLayCurse
提出日時 2019-08-21 05:59:12
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 20 ms / 2,000 ms
コード長 2,183 bytes
コンパイル時間 2,717 ms
コンパイル使用メモリ 208,496 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-16 17:24:39
合計ジャッジ時間 4,265 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 1 ms
5,376 KB
testcase_04 AC 2 ms
5,376 KB
testcase_05 AC 2 ms
5,376 KB
testcase_06 AC 2 ms
5,376 KB
testcase_07 AC 2 ms
5,376 KB
testcase_08 AC 2 ms
5,376 KB
testcase_09 AC 2 ms
5,376 KB
testcase_10 AC 2 ms
5,376 KB
testcase_11 AC 3 ms
5,376 KB
testcase_12 AC 2 ms
5,376 KB
testcase_13 AC 3 ms
5,376 KB
testcase_14 AC 2 ms
5,376 KB
testcase_15 AC 20 ms
5,376 KB
testcase_16 AC 20 ms
5,376 KB
testcase_17 AC 20 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 2 ms
5,376 KB
testcase_20 AC 2 ms
5,376 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
In function 'S chmax(S&, T) [with S = int; T = int]',
    inlined from 'int main()' at main.cpp:84:8:
main.cpp:60:3: warning: 'res' is used uninitialized [-Wuninitialized]
   60 |   if(a<b){
      |   ^~
main.cpp: In function 'int main()':
main.cpp:71:20: note: 'res' was declared here
   71 |   int KL2GvlyY, i, res, s, x, y;
      |                    ^~~

ソースコード

diff #

#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S min_L(S a,T b){
  return a<=b?a:b;
}
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(int &x){
  int k, m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmax(S &a, T b){
  if(a<b){
    a=b;
  }
  return a;
}
int N;
int A[200000];
int Q;
int T;
int V;
int main(){
  int KL2GvlyY, i, res, s, x, y;
  rd(N);
  {
    int Lj4PdHRW;
    for(Lj4PdHRW=0;Lj4PdHRW<(N);Lj4PdHRW++){
      rd(A[Lj4PdHRW]);
    }
  }
  rd(Q);
  s = 0;
  for(i=0;i<(24);i++){
    s += A[i];
  }
  chmax(res, s);
  for(i=(24);i<(N);i++){
    s += A[i] - A[i-24];
    chmax(res, s);
  }
  for(KL2GvlyY=0;KL2GvlyY<(Q);KL2GvlyY++){
    rd(T);T += (-1);
    rd(V);
    A[T] = V;
    x =max_L(0, T-24);
    y =min_L(N-1, T+24);
    s = 0;
    for(i=(x);i<(x+24);i++){
      s+= A[i];
    }
    chmax(res, s);
    for(i=(x+24);i<(y+1);i++){
      s += A[i] - A[i-24];
      chmax(res, s);
    }
    wt_L(res);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190820-1

// --- original code ---
// int N, A[2d5], Q, T, V;
// {
//   int i, x, y, s, res;
//   rd(N,A(N),Q);
// 
//   s = 0;
//   rep(i,24) s += A[i];
//   res >?= s;
//   rep(i,24,N){
//     s += A[i] - A[i-24];
//     res >?= s;
//   }
//   
//   rep(Q){
//     rd(T--,V);
//     A[T] = V;
//     x = max(0, T-24);
//     y = min(N-1, T+24);
// 
//     s = 0;
//     rep(i,x,x+24) s+= A[i];
//     res >?= s;
//     rep(i,x+24,y+1){
//       s += A[i] - A[i-24];
//       res >?= s;
//     }
// 
//     wt(res);
//   }
// }
0