結果
| 問題 | 
                            No.2662 Installing Cell Towers
                             | 
                    
| ユーザー | 
                             | 
                    
| 提出日時 | 2023-03-04 16:22:27 | 
| 言語 | C++17  (gcc 13.3.0 + boost 1.87.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 38 ms / 2,000 ms | 
| コード長 | 2,229 bytes | 
| コンパイル時間 | 2,061 ms | 
| コンパイル使用メモリ | 194,760 KB | 
| 最終ジャッジ日時 | 2025-02-11 05:18:22 | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 18 | 
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define fix(x) fixed << setprecision(x)
#define eb emplace_back
constexpr char nl='\n';
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<long long>;
using vvl = vector<vector<long long>>;
using vs = vector<string>;
using pl = pair<long long, long long>;
template <typename T> inline bool chmin(T& a, const T& b) {bool compare = a > b; if (a > b) a = b; return compare;}
template <typename T> inline bool chmax(T& a, const T& b) {bool compare = a < b; if (a < b) a = b; return compare;}
template<class T>using rp_queue=priority_queue<T,vector<T>,greater<T>>;
void fast_io(){cin.tie(nullptr);ios_base::sync_with_stdio(false);}
template <typename T> T gcd(T a, T b) {if (b == 0)return a; else return gcd(b, a % b);}
template <typename T> inline T lcm(T a, T b) {return a /gcd(a, b)*b;}
const ld PI = acos(-1);
void solve(){
  int N,M;cin>>N>>M;
  vl ans(N+2),S(N+2);
  //区間[a,b)に加算する
  auto add_ans=[&](ll a,ll b,ll m)->void{
    ans[a]+=m;
    ans[b]-=m;
  };
  auto plus=[&](ll a,ll b,ll p=1)->void{
    S[a]+=p;
    S[b]-=p;
  };
  while(M--){
    ll p,q;cin>>p>>q;
    //pによって2つの区間に分けられる
    //[1,p)
    ll a=q-p;
    if(a>=0){
      //全区間に対して適用する
      add_ans(1,p,a);
      plus(1,p);
    }else{
      //[1,p) -> [1,abs(a))+ [abs(a)+1,p) 
      add_ans(min<ll>(abs(a)+1,p),p,a);
      plus(min<ll>(abs(a)+1,p),p);
    }
    //[p,N+1)
    ll b=q+p;
    if(b-p>=0){
      //bによってさらに2つの区間に分けられる
      //[p,N+1) -> [p,b) + [b+1,N+1)
      add_ans(p,min<ll>(b+1,N+1),b);
      plus(p,min<ll>(b+1,N+1),-1);
    }else{
      //全ての区間に対して適用する
      //全ての区間がプラスなのでそのまま足す
      add_ans(p,N+1,b);
      plus(p,N+1,-1);
    }
  }
  for(ll i=1;i<=N;i++){
    S[i+1]+=S[i];
    ans[i+1]+=ans[i];
  }
  for(int i=1;i<=N;i++){
    cout<<ans[i]+S[i]*i<<" ";
  }
  cout<<endl;
}
int main(){
  fast_io();
  int num_tc = 1;
  //cin >> num_tc;
  rep(tc,num_tc){
    //cout << "Case #" << tc+1 << ": " ;// << endl;
    solve();
  }
}