結果
問題 | No.1386 Range add Simulation |
ユーザー |
👑 ![]() |
提出日時 | 2021-02-10 16:55:21 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 90 ms / 2,000 ms |
コード長 | 1,271 bytes |
コンパイル時間 | 2,006 ms |
コンパイル使用メモリ | 197,820 KB |
最終ジャッジ日時 | 2025-01-18 17:04:41 |
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 49 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:23:10: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 23 | scanf("%d%d",&N,&Q); | ~~~~~^~~~~~~~~~~~~~ main.cpp:30:23: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 30 | int c,s; scanf("%d%d",&c,&s); s--; | ~~~~~^~~~~~~~~~~~~~
ソースコード
#include <bits/stdc++.h> using namespace std; using LL=long long; #define rep(i,n) for(int i=0; i<(n); i++) struct Query{ int c,i,j; }; int N,Q; LL B[100000]; int ddA[100002]; vector<Query> ans; void Q1(int i){ ans.push_back({1,i+1,0}); B[i]++; } void Q2(int i){ ans.push_back({2,i+1,0}); B[i]--; } void Q3(int i,int j){ ans.push_back({3,i+1,j+1}); B[i]+=B[j]; } void Q4(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); Q3(i,i); if(k&1) Q1(i); } if(k<0){ make_k(i,-((-k)/2)); Q3(i,i); if(k&1) Q2(i); } } int main(){ scanf("%d%d",&N,&Q); rep(i,N) B[i]=0; LL cB[3]={}; rep(i,Q){ int c,s; scanf("%d%d",&c,&s); s--; if(c==1){ Q1(s); if(s<N-1) Q1(s+1); } if(c==2){ cB[0]+=(s+1ll)*(s+1ll); cB[1]-=(s*2+1); cB[2]+=2; if(s<N-2) Q2(s+2); if(s<N-3) Q2(s+3); } } for(int i=2; i>=0; i--){ if(i<N){ cB[i]+=B[i]; Q4(i,i); make_k(i,cB[i]); } rep(i,N-1) Q3(i+1,i); } 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; }