結果
| 問題 |
No.2662 Installing Cell Towers
|
| ユーザー |
|
| 提出日時 | 2024-03-07 22:54:35 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 48 ms / 2,000 ms |
| コード長 | 1,060 bytes |
| コンパイル時間 | 2,134 ms |
| コンパイル使用メモリ | 201,012 KB |
| 最終ジャッジ日時 | 2025-02-20 01:46:21 |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 18 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int N,M; cin >> N >> M;
vector<vector<long long>> add(N);
while(M--){
int pos,x; cin >> pos >> x; pos--;
add.at(pos).push_back(x);
}
vector<long long> answer(N),minus(N);
for(int i=0; i<N; i++) for(auto x : add.at(i)) answer.at(i) += x;
long long now = 0,sum = 0;
for(int i=0; i<N; i++){
now -= minus.at(i);
sum -= now;
answer.at(i) += sum;
for(auto x : add.at(i)){
now++; sum += x;
if(i+x+1 < N) minus.at(i+x+1)++;
}
}
now = 0,sum = 0;
minus.assign(N,0);
for(int i=N-1; i>=0; i--){
now -= minus.at(i);
sum -= now;
answer.at(i) += sum;
for(auto x : add.at(i)){
now++; sum += x;
if(i-x-1 >= 0) minus.at(i-x-1)++;
}
}
for(int i=0; i<N; i++){
if(i) cout << " ";
cout << answer.at(i);
}
cout << endl;
}