結果
| 問題 |
No.1386 Range add Simulation
|
| コンテスト | |
| ユーザー |
蜜蜂
|
| 提出日時 | 2021-02-07 18:15:23 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 126 ms / 2,000 ms |
| コード長 | 3,626 bytes |
| コンパイル時間 | 1,723 ms |
| コンパイル使用メモリ | 172,952 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-07-04 13:14:11 |
| 合計ジャッジ時間 | 19,080 ms |
|
ジャッジサーバーID (参考情報) |
judge3 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 49 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define fi first
#define se second
#define pb push_back
vector<int> operation;
random_device seed;
mt19937 randint(seed());
int grr(int mi, int ma) { // [mi, ma)
return mi + randint() % (ma - mi);
}
void op(ll x){
if(x==0){
return;
}
if(x>0){
if(x%2==0){
operation.pb(3);
op(x/2);
}
else{
operation.pb(1);
op(x-1);
}
return;
}
if(x<0){
if(x%2==0){
operation.pb(3);
op(x/2);
}
else{
operation.pb(2);
op(x+1);
}
}
}
int main(){
int n,q;
cin>>n>>q;
ll first[n]={};
ll second[n]={};
for(int i=0;i<q;i++){
int c;
cin>>c;
if(c==1){
int s;
cin>>s;
if(s==1){
first[0]+=1;
if(1<n){
first[1]+=3;
}
if(2<n){
first[2]+=2;
}
}
if(s==2){
first[1]+=1;
if(2<n){
first[2]+=2;
}
}
if(s>=3){
if(s<n){
first[s]+=1;
}
first[s-1]+=1;
}
}
if(c==2){
int s;
cin>>s;
if(s==1){
first[0]+=1;
if(1<n){
first[1]-=1;
}
if(2<n){
first[2]+=1;
}
if(3<n){
first[3]-=1;
}
}
if(s>=2){
ll z=s;
z*=z;
first[0]+=s*s;
first[1]-=2*s-1;
if(2<n){
first[2]+=2;
}
if(s+1<n){
first[s+1]-=1;
}
if(s+2<n){
first[s+2]-=1;
}
}
}
}
for(int i=0;i<n;i++){
//cout<<first[i]<<" ";
}
//cout<<endl;
//初期
/*for(int i=3;i<n;i++){
first[i]+=first[i-1];
}
for(int i=0;i<n;i++){
cout<<first[i]<<" ";
}
cout<<endl;*/
//imos1
/*for(int i=0;i<n;i++){
first[i]+=second[i];
}*/
/*for(int i=0;i<n;i++){
cout<<first[i]<<" ";
}
cout<<endl;*/
//imos1後の調整
/*for(int i=2;i<n;i++){
first[i]+=first[i-1];
}
for(int i=0;i<n;i++){
cout<<first[i]<<" ";
}
cout<<endl;*/
/*for(int i=1;i<n;i++){
first[i]+=first[i-1];
}
for(int i=0;i<n;i++){
cout<<first[i]<<" ";
}
cout<<endl;*/
//cout<<"/////////////////"<<endl;
int count=0;
for(int i=0;i<n;i++){
//cout<<i<<":";
operation.clear();
op(first[i]);
count+=operation.size();
reverse(operation.begin(),operation.end());
for(int x:operation){
if(x==1||x==2){
//cout<<x<<" "<<i+1<<"\n";
}
else{
//cout<<x<<" "<<i+1<<" "<<i+1<<"\n";
}
//cout<<x<<" ";
}
}
//cout<<endl;
for(int i=3;i<n;i++){
count++;
//cout<<3<<" "<<i+1<<" "<<i<<"\n";
}
for(int i=2;i<n;i++){
count++;
//cout<<3<<" "<<i+1<<" "<<i<<"\n";
}
for(int i=1;i<n;i++){
count++;
//cout<<3<<" "<<i+1<<" "<<i<<"\n";
}
cout<<count<<endl;
for(int i=0;i<n;i++){
//cout<<i<<":";
operation.clear();
op(first[i]);
//count+=operation.size();
reverse(operation.begin(),operation.end());
for(int x:operation){
if(x==1||x==2){
cout<<x<<" "<<i+1<<"\n";
}
else{
cout<<x<<" "<<i+1<<" "<<i+1<<"\n";
}
//cout<<x<<" ";
}
}
//cout<<endl;
for(int i=3;i<n;i++){
//count++;
cout<<3<<" "<<i+1<<" "<<i<<"\n";
}
for(int i=2;i<n;i++){
//count++;
cout<<3<<" "<<i+1<<" "<<i<<"\n";
}
for(int i=1;i<n;i++){
//count++;
cout<<3<<" "<<i+1<<" "<<i<<"\n";
}
}
蜜蜂