結果
問題 | No.619 CardShuffle |
ユーザー | kopricky |
提出日時 | 2017-12-30 20:26:10 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
WA
|
実行時間 | - |
コード長 | 5,094 bytes |
コンパイル時間 | 1,589 ms |
コンパイル使用メモリ | 175,548 KB |
実行使用メモリ | 16,588 KB |
最終ジャッジ日時 | 2024-06-02 05:31:13 |
合計ジャッジ時間 | 4,960 ms |
ジャッジサーバーID (参考情報) |
judge4 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
6,816 KB |
testcase_01 | AC | 2 ms
6,940 KB |
testcase_02 | WA | - |
testcase_03 | AC | 2 ms
6,940 KB |
testcase_04 | AC | 1 ms
6,940 KB |
testcase_05 | WA | - |
testcase_06 | AC | 1 ms
6,940 KB |
testcase_07 | AC | 2 ms
6,940 KB |
testcase_08 | WA | - |
testcase_09 | AC | 1 ms
6,940 KB |
testcase_10 | AC | 2 ms
6,944 KB |
testcase_11 | AC | 2 ms
6,940 KB |
testcase_12 | AC | 2 ms
6,940 KB |
testcase_13 | AC | 1 ms
6,944 KB |
testcase_14 | AC | 2 ms
6,944 KB |
testcase_15 | AC | 1 ms
6,944 KB |
testcase_16 | WA | - |
testcase_17 | WA | - |
testcase_18 | WA | - |
testcase_19 | WA | - |
testcase_20 | WA | - |
testcase_21 | AC | 85 ms
15,800 KB |
testcase_22 | AC | 82 ms
15,160 KB |
testcase_23 | AC | 83 ms
15,540 KB |
testcase_24 | WA | - |
testcase_25 | WA | - |
testcase_26 | AC | 106 ms
16,212 KB |
testcase_27 | WA | - |
testcase_28 | AC | 106 ms
15,292 KB |
testcase_29 | AC | 106 ms
16,332 KB |
testcase_30 | AC | 99 ms
15,956 KB |
testcase_31 | AC | 2 ms
6,940 KB |
testcase_32 | WA | - |
testcase_33 | AC | 94 ms
15,820 KB |
testcase_34 | AC | 98 ms
15,928 KB |
testcase_35 | WA | - |
ソースコード
#include <bits/stdc++.h> #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i) #define each(a,b) for(auto (a): (b)) #define all(v) (v).begin(),(v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define cmx(x,y) x=max(x,y) #define cmn(x,y) x=min(x,y) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<<endl #define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl #define svec(v) cout<<#v<<":";rep(kbrni,v.size())cout<<" "<<v[kbrni];cout<<endl #define sset(s) cout<<#s<<":";each(kbrni,s)cout<<" "<<kbrni;cout<<endl #define smap(m) cout<<#m<<":";each(kbrni,m)cout<<" {"<<kbrni.first<<":"<<kbrni.second<<"}";cout<<endl using namespace std; typedef pair<int,int> P; typedef pair<ll,ll> pll; typedef vector<int> vi; typedef vector<vi> vvi; typedef vector<ll> vl; typedef vector<vl> vvl; typedef vector<double> vd; typedef vector<P> vp; typedef vector<string> vs; const int MAX_N = 100005; ll add(ll x,ll y) { return (x + y)%MOD; } ll sub(ll x,ll y) { return (x+MOD-y)%MOD; } ll mul(ll x,ll y) { return x*y%MOD; } struct monoid { ll a,b,c; int type; monoid(){}; monoid(ll x,ll y,ll z,int flag) : a(x), b(y), c(z), type(flag){}; monoid operator*(const monoid& another){ if(this->type == 2 || another.type == 2){ if(this->type == 2){ if(another.type == 2){ return monoid(0,0,0,2); }else{ return monoid(another.a,another.b,another.c,another.type); } }else{ return monoid(this->a,this->b,this->c,this->type); } } if(this->type==0){ if(another.type==0){ return monoid(this->a,add(add(this->b,mul(this->c,another.a)),another.b),another.c,0); }else{ return monoid(this->a,this->b,mul(this->c,another.a),0); } }else{ if(another.type==0){ return monoid(mul(this->a,another.a),another.b,another.c,0); }else{ return monoid(mul(this->a,another.a),0,0,1); } } } }; template<typename V> class segtree { private: int n,sz; vector<V> node; public: segtree(vector<V>& v){ sz = (int)v.size(); n = 1; while(n < sz){ n *= 2; } node.resize(2*n-1); rep(i,sz){ node[i+n-1] = v[i]; } for(int i=n-2; i>=0; i--){ node[i] = node[i*2+1]*node[i*2+2]; } } void update(int k,V a) { k += n-1; node[k] = a; while(k>0){ k = (k-1)/2; node[k] = node[2*k+1]*node[2*k+2]; } } V query(int a,int b,int k=0,int l=0,int r=-1) { if(r < 0) r = n; if(r <= a || b <= l){ return monoid(0,0,0,2); } if(a <= l && r <= b){ return node[k]; }else{ V vl = query(a,b,2*k+1,l,(l+r)/2); V vr = query(a,b,2*k+2,(l+r)/2,r); return vl*vr; } } void print() { rep(i,sz){ cout << query(i,i+1) << " "; } cout << endl; } }; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; cin >> n; vs s(n); rep(i,n){ cin >> s[i]; } vector<monoid> vec(n); for(int i=1;i<n;i+=2){ if(s[i] == "*"){ vec[(i-1)/2] = monoid(stoi(s[i+1]),0,0,1); }else{ vec[(i-1)/2] = monoid(1,0,stoi(s[i+1]),0); } } segtree<monoid> sg(vec); int q; cin >> q; rep(i,q){ string t; int x,y; cin >> t >> x >> y; --x,--y; if(t == "!"){ if(x % 2 == 1){ monoid xx,yy; if(s[y] == "*"){ xx = monoid(stoi(s[x+1]),0,0,1); }else{ xx = monoid(1,0,stoi(s[x+1]),0); } if(s[x] == "*"){ yy = monoid(stoi(s[y+1]),0,0,1); }else{ yy = monoid(1,0,stoi(s[y+1]),0); } sg.update((x-1)/2,xx); sg.update((y-1)/2,yy); }else{ monoid xx,yy; if(s[x-1] == "*"){ xx = monoid(stoi(s[y]),0,0,1); }else{ xx = monoid(1,0,stoi(s[y]),0); } if(s[y-1] == "*"){ yy = monoid(stoi(s[x]),0,0,1); }else{ yy = monoid(1,0,stoi(s[x]),0); } sg.update((x-1)/2,xx); sg.update((y-1)/2,yy); } swap(s[x],s[y]); }else{ monoid res = sg.query(x/2,y/2); cout << add(mul(stoi(s[x]),res.a),add(res.b,res.c)) << "\n"; } } return 0; }