結果
問題 | No.1386 Range add Simulation |
ユーザー | 👑 Nachia |
提出日時 | 2021-02-07 22:33:10 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 103 ms / 2,000 ms |
コード長 | 1,712 bytes |
コンパイル時間 | 1,877 ms |
コンパイル使用メモリ | 198,652 KB |
最終ジャッジ日時 | 2025-01-18 14:58:21 |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 1 |
other | AC * 49 |
コンパイルメッセージ
main.cpp: In function ‘int main()’: main.cpp:35:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 35 | scanf("%d%d",&N,&Q); | ~~~~~^~~~~~~~~~~~~~ main.cpp:36:40: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result] 36 | A.resize(Q); rep(i,Q){ int c,s; scanf("%d%d",&c,&s); s--; A[i]={c,s}; } | ~~~~~^~~~~~~~~~~~~~
ソースコード
#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; }