QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#257249#6435. Paimon Segment TreeSatsukiRE 0ms0kbC++173.6kb2023-11-19 01:46:272023-11-19 01:46:28

Judging History

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

  • [2023-11-19 01:46:28]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:0kb
  • [2023-11-19 01:46:27]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
const int N = 50010;
typedef long long ll;
const int mod = 1e9 + 7;

struct Matrix{
	int n,m;
	using point_t = ll;
	vector<vector<point_t>> g;
	Matrix(int n, int m) :n(n),m(m) {};
	
	void clear(){
		for(auto& row : g) {
			std::fill(row.begin(), row.end(), 0);
		}
		for(int i = 1;i <= n;i++)g[i][i] = 1;
	}
	friend void operator^(Matrix &a,Matrix b){
		
		int cnt = 0;
		for(int i=1;i<=a.n;i++)
			for(int j= a.n;j>=i + 1;j--){
				for(int k=1;k<j ;k++)
					(a.g[i][j]+=a.g[i][k]*b.g[k][j]) %= mod,cnt++;
			}
		// cout << cnt << endl;
		
	}

	
};

#define ls (u << 1)
#define rs (u << 1 | 1)
#define A(u) (tr[u].A)
#define mk(u) (tr[u].mk)

struct node
{
	int l, r;
	Matrix A = Matrix(1, 4);
	Matrix mk = Matrix(4, 4);
	bool st = false;
}tr[N << 2];
int a[N];
void mul(Matrix &a,Matrix b){
		
		int cnt = 0;
		for(int i=1;i<=a.n;i++)
			for(int j=b.m;j>=i;j--){
				int t = a.g[i][j];
				for(int k=j;k>=i;k--)
					(a.g[i][j]+=a.g[i][k]*b.g[k][j] % mod);
				(a.g[i][j] -= t) %= mod;
			}
			cout << cnt << endl;
	}
void add(Matrix &a,Matrix b,Matrix c)
{
	for(int i = 1;i <= 1;i++)
		for(int j = 1;j <= 4;j++)
		{
			a.g[i][j] = (b.g[i][j] + c.g[i][j]) % mod;
		}
}


void pushup(int u)
{
	add(A(u), A(ls), A(rs));
}
Matrix e = Matrix(4,4);

void build(int u,int l,int r)
{
	if(l == r)
	{
		tr[u] = {l,r};
		A(u).g[1][1] = 1;
		A(u).g[1][2] = a[l];
		A(u).g[1][3] = a[l] * a[l] % mod;
		A(u).g[1][4] = a[l] * a[l] % mod;
		mk(u).clear();
	}
	else 
	{
		int mid = l + r >> 1;
		tr[u] = {l,r};
		mk(u).clear();
		build(ls, l, mid);
		build(rs, mid + 1, r);
		pushup(u);
	}
}

void pushdown(int u)
{
	mul(A(ls) , mk(u));
	mk(ls) ^ mk(u);
	mul(A(rs) , mk(u));
	mk(rs) ^ mk(u);
	mk(u).clear();
	tr[u].st = false;
	tr[ls].st = true;
	tr[rs].st = true;
}
Matrix B = Matrix(4,4);
void upd(int u,int l,int r,int k)
{
	if(tr[u].l >= l && tr[u].r <= r)
	{
		B.g[1][2] = k;
		B.g[1][4] =B.g[1][3] =  k * k % mod;
		B.g[2][3] =B.g[2][4]= 2 * k % mod;
		mul(A(u), B);
		mk(u) ^ B;
		tr[u].st = true;
	}
	else 
	{
		int mid = tr[u].l + tr[u].r >> 1;
		if(tr[u].st)
		pushdown(u);
		if(l <= mid)upd(ls, l, r, k);
		if(r > mid)upd(rs, l ,r ,k);
		pushup(u);
	}
}

int que(int u,int l,int r)
{
	if(tr[u].l >= l && tr[u].r <= r)
	{
		return A(u).g[1][4];
	}
	else 
	{
		int mid = tr[u].l + tr[u].r >> 1;
		int res = 0;
		if(tr[u].st)
		pushdown(u);
		if(l <= mid)res += que(ls, l, r);
		if(r > mid)res = (res + que(rs, l, r)) % mod;
		return res;
	}
}


struct qu
{
	int l,r,k,id;
}modi[N];
int ans[N];
vector<qu> q[N];

void solve()
{
	int n,m,k;cin >> n >> m >> k;
	for(int i = 1;i <= n;i++)cin >> a[i];
	build(1,1,n);
	for(int i = 1;i <= m;i++)
	{
		cin >> modi[i].l >> modi[i].r >> modi[i].k;
	}
	for(int i = 1;i <= k;i++)
	{
		int l,r;cin >> l >> r;
		int x,y;cin >> x >> y;
		if(x)
		q[x - 1].push_back({l, r, -1, i});
		q[y].push_back({l, r, 1, i});
	}
	if(n >= 1000)return;
	for(int i = 0;i <= m;i++)
	{
		if(i)
		{
			upd(1, modi[i].l, modi[i].r, modi[i].k);
			if(modi[i].l > 1)
			upd(1, 1, modi[i].l - 1, 0);
			if(modi[i].r < n)
			upd(1, modi[i].r + 1, n, 0);
		}
		for(auto t : q[i])
		{
			// cout << t.id <<" " << que(1,t.l,t.r) << endl;
			(ans[t.id] += t.k * que(1, t.l, t.r)) %= mod;
		}
	}
	for(int i = 1;i <= k;i++)
	{
		cout << (ans[i] + mod)% mod << endl;
	}
}
signed main()
{
	ios::sync_with_stdio(false);cin.tie(0);
	e.clear();
	B.g[3][3] = 1;
	B.g[3][4] = 1;
	B.g[4][4] = 1;
	B.g[1][1] = 1;
	B.g[2][2] = 1;
	solve();
}

詳細信息

Test #1:

score: 0
Runtime Error

input:

3 1 1
8 1 6
2 3 2
2 2 0 0

output:


result: