P8527 wa 求助
  • 板块题目总版
  • 楼主pystraf11
  • 当前回复0
  • 已保存回复0
  • 发布时间2025/6/15 11:48
  • 上次更新2025/6/15 23:44:15
查看原帖
P8527 wa 求助
1068414
pystraf11楼主2025/6/15 11:48
#pragma GCC optimize(2)
#include <bits/stdc++.h>
using namespace std;

using i64 = long long;
using ui64 = unsigned long long;
using i128 = __int128;
using ui128 = unsigned __int128;
using f4 = float;
using f8 = double;
using f16 = long double;

template<class T>
bool chmax(T &a, const T &b){
	if(a < b){ a = b; return true; }
	return false;
}

template<class T>
bool chmin(T &a, const T &b){
	if(a > b){ a = b; return true; }
	return false;
}

namespace fft {
	struct complex {
	    f8 x, y;
	    inline complex(f8 _x = 0.0, f8 _y = 0.0) : x(_x), y(_y) {}
	    inline complex operator + (const complex& b) const {
	        return complex(x + b.x, y + b.y);
	    }
	    inline complex operator - (const complex& b) const {
	        return complex(x - b.x, y - b.y);
	    }
	    inline complex operator * (const complex& b) const {
	        return complex(x * b.x - y * b.y, x * b.y + y * b.x);
	    }
	};
	
	constexpr double pi = acos(-1.0);
	inline void fft(vector<complex>& a, int inv, const vector<int>& rev) {
		int n = a.size(), bit = 0;
    	while ((1 << bit) < n) bit++;
    	for (int i = 0; i < n; i++) if (i < rev[i]) swap(a[i], a[rev[i]]);
        
	    for (int mid = 1; mid < n; mid <<= 1) {
	        complex wn(cos(pi / mid), inv * sin(pi / mid));
	        for (int i = 0; i < n; i += mid * 2) {
	            complex w(1, 0);
	            for (int j = 0; j < mid; j++, w = w * wn) {
	                complex x = a[i + j], y = w * a[i + j + mid];
	                a[i + j] = x + y;
	                a[i + j + mid] = x - y;
	            }
	        }
	    }
	    
	    if (inv == -1) for (int i = 0; i < n; i++) a[i].x /= n;
	}
	
	template<class T>
	inline void convolution(const vector<T>& a, const vector<T>& b, vector<T>& c) {
		int n = a.size(), m = b.size(), len = 1, bit = 0;
	    while (len < n + m) len <<= 1, bit++;
	    
	    vector<int> rev(len);
	    for (int i = 0; i < len; i++) rev[i] = (rev[i >> 1] >> 1) | ((i & 1) << (bit - 1));
	    
		vector<complex> ta(len), tb(len);
		for (int i = 0; i < n; i++) ta[i] = complex(a[i], 0);
		for (int i = 0; i < m; i++) tb[i] = complex(b[i], 0);
		
		fft(ta, 1, rev), fft(tb, 1, rev);
		for (int i = 0; i < len; i++) ta[i] = ta[i] * tb[i];
		fft(ta, -1, rev);
		
		if (c.empty()) c.resize(n + m - 1);
		for (int i = 0; i < c.size(); i++) c[i] = T(ta[i].x + 0.5);
	}
}
using fft::convolution;

constexpr int B = 2048;
struct query {
	int l, r, x;
	inline query() {}
	inline query(int _l, int _r, int _x) : l(_l), r(_r), x(_x) {}
};

signed main() {
	ios::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	
	int n; cin >> n;
	vector<int> a(n), b(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	
	int m; cin >> m;
	vector<query> qry(m);
	for (auto & [l, r, x] : qry) {
		cin >> l >> r >> x;
		l--, r--, x--;
	}
	
	vector<int> p, q, r;
	auto modify = [&](int l, int r, int x) {
		for (int i = l; i <= r; i++) b[x + i - l] += a[i];
	};
	
	auto solve = [&](int bl, int br) {
		p.assign(br - bl + 1, 0), q.assign(n - br + bl, 0);
		for (int i = bl; i <= br; i++) p[i - bl] = a[i];
		for (auto & [ql, qr, qx] : qry) {
			if (ql <= bl && br <= qr) q[qx - ql + bl]++;
			else modify(max(ql, bl), min(qr, br), qx);
		}
		convolution(p, q, r);
		for (int i = 0; i < n; i++) b[i] += r[i];
	};
	
	const int blocks = (n + B - 1) / B;
	for (int i = 0; i < blocks; i++) {
		const int bl = i * B, br = min(bl + B, n) - 1;
		solve(bl, br);
	}
	for (int i = 0; i < n; i++) cout << b[i] << '\n';
	
	return 0;
}

case 2 一直过不去,求条,玄1关

2025/6/15 11:48
加载中...