結果
問題 | No.2662 Installing Cell Towers |
ユーザー |
|
提出日時 | 2023-03-05 00:25:06 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 105 ms / 2,000 ms |
コード長 | 562 bytes |
コンパイル時間 | 2,318 ms |
コンパイル使用メモリ | 194,488 KB |
最終ジャッジ日時 | 2025-02-11 05:26:48 |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 18 |
ソースコード
#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; add(ans,min(max(p-q+1,1),p),p,a); add(S,min(max(p-q+1,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; }