結果

問題 No.3265 地元に帰れば天才扱い!
ユーザー のらら
提出日時 2025-08-11 16:41:16
言語 C++23
(gcc 13.3.0 + boost 1.87.0)
結果
WA  
実行時間 -
コード長 1,068 bytes
コンパイル時間 3,457 ms
コンパイル使用メモリ 177,148 KB
実行使用メモリ 14,364 KB
最終ジャッジ日時 2025-09-06 12:32:28
合計ジャッジ時間 19,272 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample WA * 4
other RE * 21
権限があれば一括ダウンロードができます

ソースコード

diff #

//TLE解
#include <iostream>
#include <algorithm>
#include <atcoder/all>
using namespace std;
using namespace atcoder;
using ll = long long;
//#define endl "\n";
ll N, A[200009], sum[200009], Q, X[200009], Y[200009], L[200009], R[200009];
vector<ll> chg;
ll ans = 0, organs = 0, deg[200009];

int main(){
  cin >> N;
  for(int i = 1; i <= N; i++){
    cin >> A[i];
    sum[i] = sum[i - 1] + A[i];
  }
  cin >> Q;
  for(int q = 1; q <= Q; q++){
    cin >> X[q] >> Y[q] >> L[q] >> R[q];
    chg.push_back(X[q]);
  }
  sort(chg.begin(), chg.end());
  chg.erase(unique(chg.begin(), chg.end()), chg.end());
  
  for(int q = 1; q <= Q; q++){
    A[X[q]] = Y[q];
    organs += sum[R[q]] - sum[L[q] - 1];
    ll posl = lower_bound(chg.begin(), chg.end(), L[q]) - chg.begin();
    ll posr = lower_bound(chg.begin(), chg.end(), R[q] + 1) - chg.begin();
    for(int i = posl; i < posr; i++) deg[chg[i]]++;
    ans = organs;
    for(int i = 0; i < (int)chg.size(); i++) ans += (A[chg[i]] - (sum[chg[i]] - sum[chg[i] - 1])) * deg[chg[i]];
    cout << ans << endl;
  }
  return 0;
}
0