結果
| 問題 |
No.619 CardShuffle
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2017-12-30 20:26:10 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 5,094 bytes |
| コンパイル時間 | 2,251 ms |
| コンパイル使用メモリ | 175,480 KB |
| 実行使用メモリ | 15,232 KB |
| 最終ジャッジ日時 | 2024-12-22 23:24:41 |
| 合計ジャッジ時間 | 5,774 ms |
|
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 22 WA * 13 |
ソースコード
#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;
}