結果

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

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
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 8 ms
6,676 KB
testcase_05 AC 76 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 8 ms
6,676 KB
testcase_10 AC 84 ms
6,676 KB
testcase_11 AC 71 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 62 ms
6,676 KB
testcase_14 AC 87 ms
6,676 KB
testcase_15 AC 66 ms
6,676 KB
testcase_16 AC 2 ms
6,676 KB
testcase_17 AC 90 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(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;
    if(p <= b){
      add(ans,p,min(b+1,N+1),b);
      add(S,p,min(b+1,N+1),-1);
    }else{
      add(ans,p,N+1,b);
      add(S,p,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