1 条题解

  • 0
    @ 2025-9-10 9:11:36

    C++ :

    #include<cstdio>
    #include<iostream>
    #include<cmath>
    #include<algorithm>
    #include<cstring>
    #include<cstdlib>
    #include<cctype>
    #include<queue>
    using namespace std;
    #define enter puts("") 
    #define space putchar(' ')
    #define Mem(a, x) memset(a, x, sizeof(a))
    #define In inline
    typedef long long ll;
    typedef double db;
    const int INF = 0x3f3f3f3f;
    const db eps = 1e-8;
    const int maxn = 4e7 + 5;
    const int maxm = 1e5 + 10;
    const int mod = 1 << 30;
    In ll read()
    {
    	ll ans = 0;
    	char ch = getchar(), las = ' ';
    	while(!isdigit(ch)) las = ch, ch = getchar();
    	while(isdigit(ch)) ans = (ans << 1) + (ans << 3) + ch - '0', ch = getchar();
    	if(las == '-') ans = -ans;
    	return ans;
    }
    In void write(ll x)
    {
    	if(x < 0) x = -x, putchar('-');
    	if(x >= 10) write(x / 10);
    	putchar(x % 10 + '0');
    }
    
    int n, m, TYPE, a[maxn];
    int b[maxn], p[maxm], l[maxm], r[maxm];
    ll sum[maxn];
    
    In void input()
    {
    	n = read(), TYPE = read();	
      	if(TYPE) 
      	{
      		ll x = read(), y = read(), z = read();
    		b[1] = read(), b[2] = read(), m = read();
        	for(int i = 1; i <= m; ++i) p[i] = read(), l[i] = read(), r[i] = read();
        	for(int i = 3; i <= n; ++i) b[i] = (x * b[i - 1] + y * b[i - 2] + z) % mod;
        	for(int i = 1; i <= m; ++i)
          		for(int j = p[i - 1] + 1; j <= p[i]; ++j) a[j] = (b[j] % (r[i] - l[i] + 1)) + l[i];
    	}
    	else for(int i = 1; i <= n; ++i) a[i] = read();
    }
    
    deque<int> q;
    int pre[maxn], st[50], top = 0;
    In ll g(int x) {return sum[x] - sum[pre[x]];}
    In ll p_2(ll a) {return a * a;}
    
    int main()
    {
    	input();
    	for(int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i];
    	q.push_back(0); 
    	for(int i = 1; i <= n; ++i)
    	{
    		while((int)q.size() > 1 && g(q[1]) + sum[q[1]] <= sum[i]) q.pop_front();
    		pre[i] = q.front();
    		while(!q.empty() && g(q.back()) + sum[q.back()] >= g(i) + sum[i]) q.pop_back();
    		q.push_back(i);
    	}
    	int x = n; __int128 ans = 0, tp = 1;
    	while(x)
    	{
    		tp = g(x), tp *= g(x);
    		ans += tp, x = pre[x];
    	}
    	while(ans) st[++top] = ans % 10, ans /= 10;
    	while(top) write(st[top--]); enter;
    	return 0;
    }
    
    • 1

    信息

    ID
    3820
    时间
    10000ms
    内存
    1024MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者