結果
| 問題 |
No.1386 Range add Simulation
|
| コンテスト | |
| ユーザー |
Nachia
|
| 提出日時 | 2021-02-07 21:12:53 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 1,822 bytes |
| コンパイル時間 | 3,623 ms |
| コンパイル使用メモリ | 198,228 KB |
| 最終ジャッジ日時 | 2025-01-18 14:20:36 |
|
ジャッジサーバーID (参考情報) |
judge1 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | WA * 10 RE * 39 |
コンパイルメッセージ
main.cpp: In function ‘int main()’:
main.cpp:30:8: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
30 | scanf("%d%d",&N,&Q);
| ~~~~~^~~~~~~~~~~~~~
main.cpp:31:40: warning: ignoring return value of ‘int scanf(const char*, ...)’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
31 | 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[100001];
vector<QueryA> A;
vector<Query> ans;
LL topA=0, topdA=0, topddA=0;
LL Alast2=0, Alast1=0;
void query_1(int i){ ans.push_back({1,i,0}); B[i]++; }
void query_2(int i){ ans.push_back({2,i,0}); B[i]--; }
void query_3(int i,int j){ ans.push_back({3,i,j}); B[i]+=B[j]; }
void query_4(int i,int j){ ans.push_back({4,i,j}); 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_4(i,i); if(k&1) query_2(i); }
}
LL add_si(LL s,LL i){ s=abs(s-i)+1; return s*s; }
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+1) ddA[i]=0;
rep(i,N){
if(A[i].c==1){
ddA[A[i].s]+=2;
if(A[i].s<=N-2) Alast2 += add_si(N-2,A[i].s);
if(A[i].s<=N-1) Alast1 += add_si(N-1,A[i].s);
}
if(A[i].c==2){
ddA[A[i].s+1]-=2;
topA+=LL(A[i].s+1)*(A[i].s+1);
topdA-=(A[i].s+1)*2-1;
topddA+=2;
if(A[i].s>=N-2) Alast2 += add_si(N-2,A[i].s);
if(A[i].s>=N-1) Alast1 += add_si(N-1,A[i].s);
}
}
rep(i,N) B[i]=0;
make_k(0,topA);
make_k(N-1,topdA);
make_k(N-2,topddA);
for(int i=1; i<N-2; i++){
query_3(i,i-1);
query_3(i,N-1);
query_3(N-1,N-2);
if(ddA[i]>0) rep(j,ddA[i]) query_1(N-2);
if(ddA[i]<0) rep(j,-ddA[i]) query_2(N-2);
}
query_4(N-2,N-2); make_k(N-2,Alast2);
query_4(N-1,N-1); make_k(N-1,Alast1);
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;
}
Nachia