結果

問題 No.1386 Range add Simulation
ユーザー maple116maple116
提出日時 2021-02-07 22:53:58
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 4,992 bytes
コンパイル時間 4,609 ms
コンパイル使用メモリ 211,832 KB
実行使用メモリ 8,476 KB
最終ジャッジ日時 2023-09-18 00:06:34
合計ジャッジ時間 38,722 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 AC 4 ms
4,380 KB
testcase_04 AC 5 ms
4,376 KB
testcase_05 AC 5 ms
4,380 KB
testcase_06 WA -
testcase_07 AC 300 ms
5,004 KB
testcase_08 WA -
testcase_09 AC 305 ms
5,012 KB
testcase_10 AC 298 ms
5,000 KB
testcase_11 WA -
testcase_12 AC 605 ms
6,872 KB
testcase_13 WA -
testcase_14 AC 610 ms
6,956 KB
testcase_15 WA -
testcase_16 AC 605 ms
8,476 KB
testcase_17 WA -
testcase_18 WA -
testcase_19 WA -
testcase_20 AC 606 ms
8,124 KB
testcase_21 WA -
testcase_22 WA -
testcase_23 WA -
testcase_24 WA -
testcase_25 WA -
testcase_26 WA -
testcase_27 WA -
testcase_28 WA -
testcase_29 WA -
testcase_30 WA -
testcase_31 WA -
testcase_32 WA -
testcase_33 WA -
testcase_34 WA -
testcase_35 AC 2 ms
4,384 KB
testcase_36 AC 9 ms
4,376 KB
testcase_37 AC 13 ms
4,376 KB
testcase_38 AC 11 ms
4,380 KB
testcase_39 AC 10 ms
4,380 KB
testcase_40 WA -
testcase_41 WA -
testcase_42 WA -
testcase_43 WA -
testcase_44 WA -
testcase_45 WA -
testcase_46 WA -
testcase_47 WA -
testcase_48 WA -
testcase_49 WA -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//g++ hoge.cpp (-std=c++17) -I . で実行
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> prl;
typedef vector<ll> vcl;
typedef map<ll,ll> mapl;
typedef unordered_map<ll,ll> umap;
#define pb push_back
#define all(v) v.begin(), v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repi(i,a,b) for(int i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
#define rept(itr,v) for(auto itr=v.begin();itr!=v.end();itr++)
#define rept1(itr,v) for(auto itr=v.begin()+1;itr!=v.end();itr++)
#define rept2(itr,v) for(auto itr=v.begin();itr!=v.end()-1;itr++)
#define print(x) cout << (x) << endl;
#define fprint(x) printf("%.15lf\n",(x));
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define print3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl;
#define YesNo(test) cout << ((test) ? "Yes" : "No") << endl
#define debug cout << "debug_print" << endl
#define Bint boost::multiprecision::cpp_int
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
ll myceil(ll a, ll b) { return (a+b-1) / b; }
//const ll mod = 1e9+7;
//const ll mod = 998244353;
//typedef modint1000000007 mint;
//typedef modint998244353 mint;
//typedef modint mint
//cout << sum.val() << endl;
//mint::set_mod(mod); modが固定でないとき

ll n,q,c[50000],s[50000],a,b,d,x,js[100005];
vector<pair<ll,prl>> vs[20];

int main() {
    // your code goes here
    cin >> n >> q;
    rep(i,1,q){
        cin >> c[i] >> s[i];
    }
    if(n<=10){
        rep(i,1,q){
            rep(j,1,n){
                if(c[i]==1 && j>=s[i]) js[j] += (j-s[i]+1)*(j-s[i]+1);
                if(c[i]==2 && j<=s[i]) js[j] += (s[i]-j+1)*(s[i]-j+1);
            }
        }
        //rep(i,1,n) print(js[i]);
        rep(i,1,n){
            while(js[i]>0){
                x++;
                if(js[i]%2==0){
                    vs[i].pb({3,{i,i}});
                    js[i] /= 2;
                } else {
                    vs[i].pb({1,{i,0}});
                    js[i] -= 1;
                }
            }
        }
        print(x);
        rep(i,1,n){
            reverse(all(vs[i]));
            for(auto to: vs[i]){
                if(to.first<=2){
                    print2(to.first,to.second.first);
                } else {
                    print3(to.first,to.second.first,to.second.second);
                }
            }
        }
        return 0;
    }
    rep(i,1,q){
        if(c[i]==1){
            if(s[i]==1) a += 1;
            if(s[i]==1) b += 3;
            if(s[i]==2) b += 1;
            if(s[i]<=2) d += 2;
            if(s[i]==3) d += 1;
            if(s[i]>=4){
                x++;
                vs[1].pb({1,{s[i],0}});
            }
            if(s[i]>=3 && s[i]<=n-1){
                x++;
                vs[1].pb({1,{s[i]+1,0}});
            }
        } else {
            a += s[i]*s[i];
            b += (1 - 2 * s[i]);
            //print(b);
            if(s[i]>=2) d += 2;
            if(s[i]>=2&&s[i]<=n-2){
                x++;
                vs[1].pb({2,{s[i]+2,0}});
            }
            if(s[i]>=1&&s[i]<=n-3){
                x++;
                vs[1].pb({2,{s[i]+3,0}});
            }
        }
    }
    //print3(a,b,d);
    while(a>0){
        x++;
        if(a%2==0){
            vs[2].pb({3,{1,1}});
            a /= 2;
        } else {
            vs[2].pb({1,{1,0}});
            a -= 1;
        }
    }
    while(a<0){
        x++;
        if(a%2==0){
            vs[2].pb({3,{1,1}});
            a /= 2;
        } else {
            vs[2].pb({2,{1,0}});
            a += 1;
        }
    }
    while(b>0){
        x++;
        if(b%2==0){
            vs[3].pb({3,{2,2}});
            b /= 2;
        } else {
            vs[3].pb({1,{2,0}});
            b -= 1;
        }
    }
    while(b<0){
        x++;
        if(b%2==0){
            vs[3].pb({3,{2,2}});
            b /= 2;
        } else {
            vs[3].pb({2,{2,0}});
            b += 1;
        }
    }
    while(d>0){
        x++;
        if(d%2==0){
            vs[4].pb({3,{3,3}});
            d /= 2;
        } else {
            vs[4].pb({1,{3,0}});
            d -= 1;
        }
    }
    while(d<0){
        x++;
        if(d%2==0){
            vs[4].pb({3,{3,3}});
            d /= 2;
        } else {
            vs[4].pb({2,{3,0}});
            d += 1;
        }
    }
    print(x+(n-3)+(n-2)+(n-1));
    repr(i,4,1){
        if(i>=2) reverse(all(vs[i]));
        for(auto to: vs[i]){
            if(to.first<=2){
                print2(to.first,to.second.first);
            } else {
                print3(to.first,to.second.first,to.second.second);
            }
        }
    }
    repr(i,3,1){
        rep(j,i+1,n){
            print3(3,j,j-1);
        }
    }
    return 0;
}
0