結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 7 ms
6,676 KB
testcase_05 AC 81 ms
6,676 KB
testcase_06 AC 53 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 34 ms
6,676 KB
testcase_09 AC 7 ms
6,676 KB
testcase_10 AC 84 ms
6,676 KB
testcase_11 AC 72 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 62 ms
6,676 KB
testcase_14 AC 91 ms
6,676 KB
testcase_15 AC 69 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 91 ms
6,676 KB
testcase_18 AC 90 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;
int main(){
  int N,M;cin >> N >> M;
  vector<long long> ans(N+2),S(N+2);
  auto add = [](vector<long long> &A,int l,int r,int C)->void{
    A[l] += C;
    A[r] -= C;
  };
  while(M--){
    int p,q;cin >> p >> q;
    int a = q - p;
    if(a>=0){
      add(ans,1,p,a);
      add(S,1,p,1);
    }else{
      add(ans,min(p-q+1,p),p,a);
      add(S,min(p-q+1,p),p,1);
    }
    int b = p + q;
    add(ans,p,min(b+1,N+1),b);
    add(S,p,min(b+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 << " ";
  }
  cout<<endl;
}
0