QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#706164#8061. Add or Multiplyjerry2423Compile Error//Python32.7kb2024-11-03 08:05:492024-11-03 08:05:50

Judging History

你现在查看的是最新测评结果

  • [2024-11-03 08:05:50]
  • 评测
  • [2024-11-03 08:05:49]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define tl t[tp][p].l
#define tr t[tp][p].r
#define tlp t[tp][p].lp
#define trp t[tp][p].rp
#define LP t[tp][tlp]
#define RP t[tp][trp]
using namespace std;
const int N(200005);
const ll mod(1e9+7);
int tot[2];
ll a[N*2];
struct NODE
{
	int lp, rp, l, r;
	bool all = 0, tgl=0, tgr=0;
	ll ans=0, lans=0, rans=0, add=0;
}t[2][N*10];
bool Link(int mid, int tp) { return (a[mid*2]==tp); }
void update(int p, int tp)
{
	int l = tl, r = tr;
	int mid = l+r >> 1;
	t[tp][p].ans = ((LP.ans+RP.ans)%mod+Link(mid, tp)*(-LP.rans*LP.tgr-RP.lans*RP.tgl+LP.rans*RP.lans%mod)+mod)%mod;
	t[tp][p].ans = (t[tp][p].ans%mod+mod)%mod;
	
	t[tp][p].add = LP.add+RP.add;
	if(Link(mid, tp)) t[tp][p].add -= (LP.tgr^1)*a[mid*2-1]+(RP.tgl^1)*a[mid*2+1];

	if(LP.all && Link(mid, tp)) t[tp][p].lans = (LP.lans*RP.lans)%mod, t[tp][p].tgl = 1;
	else t[tp][p].lans = LP.lans, t[tp][p].tgl = LP.tgl;
	if(RP.all && Link(mid, tp)) t[tp][p].rans = (RP.rans*LP.rans)%mod, t[tp][p].tgr = 1;
	else t[tp][p].rans = RP.rans, t[tp][p].tgr = RP.tgr;

	t[tp][p].all = ((LP.all+RP.all == 2)&&Link(mid, tp));
}
void build(int l, int r, int tp)
{
	int p = ++tot[tp];
	if(l != r)
	{
		tl = l, tr = r;
		int mid = l+r>>1;
		tlp = tot[tp]+1;
		build(l, mid, tp);
		trp = tot[tp]+1;
		build(mid+1, r, tp);
		update(p, tp);
	}
	else 
	{
		t[tp][p].l = l, t[tp][p].r = r;
		t[tp][p].add = t[tp][p].lans = t[tp][p].rans = a[l*2-1];
		t[tp][p].all = 1;
	}
}
void modify(int p, int l, int r, int pos, int tp)
{
	if(l == r) { t[tp][p].add = t[tp][p].lans = t[tp][p].rans = a[l*2-1]; return; }
	int mid = (tl+tr)/2;
	if(pos <= mid) modify(tlp, l, mid, pos, tp);
	else modify(trp, mid+1, r, pos, tp);
	update(p, tp);
}
int main()
{
	//freopen("1.in","r",stdin);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m; cin >> n >> m;
	string inpu; cin >> inpu;
	for(int i = 0; i < n*2-1; ++i)
	{
		if(inpu[i] == '+') a[i+1] = 0;
		else if(inpu[i] == '*') a[i+1] = 1;
		else a[i+1] = inpu[i]-'0';
	}
	build(1, n, 0);
	build(1, n, 1);
	bool type = 1;
	cout<<(t[type][1].ans+t[type][1].add)%mod<<endl;
	for(int i = 1; i <= m; ++i)
	{
		char op; cin >> op;
		int x, y;
		if(op == 's')
		{
			cin >> x >> y;
			swap(a[x*2-1], a[y*2-1]);
			modify(1, 1, n, x, type);
			modify(1, 1, n, y, type);
			modify(1, 1, n, x, type^1);
			modify(1, 1, n, y, type^1);
		}
		if(op == 'f')
		{
			cin >> x;
			a[x*2] ^= 1;
			modify(1, 1, n, x, type);
			modify(1, 1, n, x+1, type);
			modify(1, 1, n, x, type^1);
			modify(1, 1, n, x+1, type^1);
		}
		if(op == 'a') type ^= 1;
		cout<<(t[type][1].ans+t[type][1].add)%mod<<endl;
	}
	return 0;
}

Details

  File "answer.code", line 9
    using namespace std;
          ^^^^^^^^^
SyntaxError: invalid syntax