結果

問題 No.2662 Installing Cell Towers
ユーザー 2bit2bit
提出日時 2023-03-05 00:36:44
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 87 ms / 2,000 ms
コード長 552 bytes
コンパイル時間 2,062 ms
コンパイル使用メモリ 203,692 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-16 02:04:37
合計ジャッジ時間 4,328 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 AC 7 ms
6,548 KB
testcase_05 AC 75 ms
6,548 KB
testcase_06 AC 53 ms
6,548 KB
testcase_07 AC 2 ms
6,548 KB
testcase_08 AC 34 ms
6,548 KB
testcase_09 AC 7 ms
6,548 KB
testcase_10 AC 83 ms
6,548 KB
testcase_11 AC 70 ms
6,548 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 63 ms
6,548 KB
testcase_14 AC 86 ms
6,676 KB
testcase_15 AC 66 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 87 ms
6,676 KB
testcase_18 AC 87 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
void add(vector<long long> &A,int l,int r,int C){
  A[l] += C;
  A[r] -= C;
}
int main(){
  int N, M;
  cin >> N >> M;
  vector<long long> ans(N + 2),S(N + 2);
  while(M--){
    int p, q;
    cin >> p >> q;
    add(ans,min(max(p - q + 1,1),p),p,q - p);
    add(S,min(max(p - q + 1,1),p),p,1);
    add(ans,p,min(p + q + 1,N + 1),p + q);
    add(S,p,min(p + q + 1,N + 1),-1);
  }
  for(int i = 1;i <= N;i++){
    S[i + 1] += S[i];
    ans[i + 1] += ans[i];
    cout << ans[i] + S[i] * i << " \n"[i==N];
  }
}
0