結果

問題 No.1386 Range add Simulation
ユーザー 👑 NachiaNachia
提出日時 2021-02-07 22:33:10
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 91 ms / 2,000 ms
コード長 1,712 bytes
コンパイル時間 4,132 ms
コンパイル使用メモリ 203,472 KB
実行使用メモリ 10,556 KB
最終ジャッジ日時 2023-09-17 22:44:46
合計ジャッジ時間 21,701 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,056 KB
testcase_01 AC 2 ms
4,996 KB
testcase_02 AC 2 ms
4,996 KB
testcase_03 AC 2 ms
4,992 KB
testcase_04 AC 2 ms
4,992 KB
testcase_05 AC 2 ms
4,996 KB
testcase_06 AC 44 ms
6,824 KB
testcase_07 AC 45 ms
6,720 KB
testcase_08 AC 45 ms
6,796 KB
testcase_09 AC 45 ms
6,700 KB
testcase_10 AC 45 ms
6,972 KB
testcase_11 AC 89 ms
10,468 KB
testcase_12 AC 89 ms
10,436 KB
testcase_13 AC 88 ms
10,432 KB
testcase_14 AC 88 ms
10,436 KB
testcase_15 AC 88 ms
10,492 KB
testcase_16 AC 89 ms
10,520 KB
testcase_17 AC 88 ms
10,480 KB
testcase_18 AC 91 ms
10,488 KB
testcase_19 AC 89 ms
10,468 KB
testcase_20 AC 90 ms
10,524 KB
testcase_21 AC 89 ms
10,484 KB
testcase_22 AC 88 ms
10,436 KB
testcase_23 AC 88 ms
10,452 KB
testcase_24 AC 90 ms
10,488 KB
testcase_25 AC 89 ms
10,480 KB
testcase_26 AC 89 ms
10,452 KB
testcase_27 AC 88 ms
10,372 KB
testcase_28 AC 88 ms
10,448 KB
testcase_29 AC 88 ms
10,468 KB
testcase_30 AC 87 ms
10,556 KB
testcase_31 AC 87 ms
10,516 KB
testcase_32 AC 88 ms
10,432 KB
testcase_33 AC 87 ms
10,496 KB
testcase_34 AC 88 ms
10,492 KB
testcase_35 AC 1 ms
4,992 KB
testcase_36 AC 10 ms
4,992 KB
testcase_37 AC 12 ms
4,992 KB
testcase_38 AC 11 ms
5,056 KB
testcase_39 AC 8 ms
4,996 KB
testcase_40 AC 89 ms
10,536 KB
testcase_41 AC 88 ms
10,496 KB
testcase_42 AC 87 ms
10,496 KB
testcase_43 AC 87 ms
10,432 KB
testcase_44 AC 88 ms
10,428 KB
testcase_45 AC 88 ms
10,512 KB
testcase_46 AC 88 ms
10,480 KB
testcase_47 AC 87 ms
10,520 KB
testcase_48 AC 87 ms
10,540 KB
testcase_49 AC 91 ms
10,472 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using LL=long long;
using ULL=unsigned long long;
#define rep(i,n) for(int i=0; i<(n); i++)

struct QueryA{ int c,s; };
struct Query{ int c,i,j; };

int N,Q;
LL B[100000];
int ddA[100002];
vector<QueryA> A;
vector<Query> ans;
LL topA=0, topdA=0, topddA=0;
LL Alast[3];

void query_1(int i){ ans.push_back({1,i+1,0}); B[i]++; }
void query_2(int i){ ans.push_back({2,i+1,0}); B[i]--; }
void query_3(int i,int j){ ans.push_back({3,i+1,j+1}); B[i]+=B[j]; }
void query_4(int i,int j){ ans.push_back({4,i+1,j+1}); B[i]-=B[j]; }
void make_k(int i,LL k){
  if(k>0){ make_k(i,k/2); query_3(i,i); if(k&1) query_1(i); }
  if(k<0){ make_k(i,-((-k)/2)); query_3(i,i); if(k&1) query_2(i); }
}
LL add_si(LL s,LL i){ s=abs(s-i)+1; return s*s; }

LL simuA[1000];
void query_A1(int s){ for(int i=s; i<N; i++) simuA[i]+=add_si(s,i); }
void query_A2(int s){ for(int i=0; i<=s; i++) simuA[i]+=add_si(s,i); }
void imos(){ rep(i,N-1) query_3(i+1,i); }

int main(){
  scanf("%d%d",&N,&Q);
  A.resize(Q); rep(i,Q){ int c,s; scanf("%d%d",&c,&s); s--; A[i]={c,s}; }

  rep(i,N) B[i]=0;

  LL reservedB[3]={};
  
  for(auto& q:A){
    if(q.c==1){
      query_1(q.s);
      if(q.s<N-1) query_1(q.s+1);
    }
    if(q.c==2){
      reservedB[0]+=add_si(q.s,0);
      reservedB[1]-=(q.s*2+1);
      reservedB[2]+=2;
      if(q.s<N-2) query_2(q.s+2);
      if(q.s<N-3) query_2(q.s+3);
    }
  }

  for(int i=2; i>=0; i--){
    if(i<N){
      reservedB[i]+=B[i];
      query_4(i,i);
      make_k(i,reservedB[i]);
    }
    imos();
  }

  printf("%d\n",(int)ans.size());
  for(auto q:ans){
    if(q.c<=2) printf("%d %d\n",q.c,q.i);
    if(q.c>=3) printf("%d %d %d\n",q.c,q.i,q.j);
  }

  return 0;
}
0