結果

問題 No.2662 Installing Cell Towers
ユーザー 2bit2bit
提出日時 2023-03-04 15:31:10
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,643 bytes
コンパイル時間 2,192 ms
コンパイル使用メモリ 208,712 KB
実行使用メモリ 9,600 KB
最終ジャッジ日時 2024-03-16 02:01:31
合計ジャッジ時間 4,673 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,548 KB
testcase_01 AC 2 ms
6,548 KB
testcase_02 AC 2 ms
6,548 KB
testcase_03 AC 2 ms
6,548 KB
testcase_04 WA -
testcase_05 AC 128 ms
9,600 KB
testcase_06 AC 60 ms
6,548 KB
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 AC 121 ms
9,600 KB
testcase_11 AC 102 ms
9,216 KB
testcase_12 AC 2 ms
6,548 KB
testcase_13 AC 48 ms
6,548 KB
testcase_14 AC 131 ms
9,600 KB
testcase_15 WA -
testcase_16 AC 2 ms
6,548 KB
testcase_17 AC 95 ms
9,600 KB
testcase_18 AC 97 ms
9,600 KB
testcase_19 WA -
testcase_20 AC 2 ms
6,548 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
#include<atcoder/lazysegtree>
using S = long long;
using F = long long;

const S INF = 8e18;

S op(S a, S b){ return std::max(a, b); }
S e(){ return -INF; }
S mapping(F f, S x){ return f+x; }
F composition(F f, F g){ return f+g; }
F id(){ return 0; }
void solve(){
  int N,M;cin>>N>>M;
  std::vector<S> A(N+1);
  atcoder::lazy_segtree<S, op, e, F, mapping, composition, id> seg(A);
  //それぞれに何回マイナスその数がされたのかを求める配列
  //imosでやる
  vl minus(N+2),plus(N+2);
  //これを区間加算を使って高速化する
  while(M--){
    ll p,q;cin>>p>>q;
    //pによって2つの区間に分けられる
    //[1,p)

    ll a=q-p;
    //aによって2つの区間に分けられる
    if(a<=0){
      //区間[abs(a),p)までに処理を行う
      seg.apply(abs(a),p,a);
      plus[abs(a)]++;
      plus[p]--;
    }else{
      seg.apply(1,p,a);
      plus[1]++;
      plus[p]--;
    }

    //[p,N+1)
    ll b=q+p;
    //bによってさらに2つの区間に分けられる
    if(b-p>=0){
      //全ての区間に対して適用する
      seg.apply(p,min<ll>(b,N+1),b);
      minus[p]++;
      minus[min<ll>(b,N+1)]--;
    }else{
      //[p,b) + [b,N+1)
      seg.apply(p,N+1,b);
      minus[p]++;
      minus[N+1]--;
    }
  }
  for(int i=1;i<=N;i++)plus[i+1]+=plus[i];
  for(int i=1;i<=N;i++)minus[i+1]+=minus[i];
  vl ans(N+1);
  for(int i=1;i<=N;i++){
    ans[i] = seg.get(i)+(plus[i]-minus[i])*i;
  }
  for(int i=1;i<=N;i++){
    cout<<ans[i]<<" ";
  }
  cout<<endl;
}
int main(){
  fast_io();
  int num_tc = 1;
  //cin >> num_tc;
  rep(tc,num_tc){
    //cout << "Case #" << tc+1 << ": " ;// << endl;
    solve();
  }
}
0