結果

問題 No.2662 Installing Cell Towers
ユーザー 2bit2bit
提出日時 2023-03-04 17:06:32
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 635 bytes
コンパイル時間 2,411 ms
コンパイル使用メモリ 203,952 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-03-16 02:03:19
合計ジャッジ時間 3,886 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 1 ms
6,676 KB
testcase_04 AC 8 ms
6,676 KB
testcase_05 AC 72 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 79 ms
6,676 KB
testcase_11 AC 68 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 61 ms
6,676 KB
testcase_14 AC 82 ms
6,676 KB
testcase_15 AC 63 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 89 ms
6,676 KB
testcase_18 AC 88 ms
6,676 KB
testcase_19 AC 2 ms
6,676 KB
testcase_20 AC 1 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(0<=a){
      add(ans,1,p,a);
      add(S,1,p,1);
    }else{
      add(ans,min(abs(a)+1,p),p,a);
      add(S,min(abs(a)+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