ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn't want to study

C*M....死于update的一个long long写成int了

心累 不想写过程了 ********

树状数组,一个平的一个斜着的,怎么斜都行

题库链接:https://nanti.jisuanke.com/t/31460

#include <iostream>
#include <cstring>

#define ll long long
#define lowbit(x) (x & -x)

using namespace std;

const int maxn = 1e5 + 20;
int n, m;
ll t[maxn];
ll t1[maxn];
ll ans[maxn];

ll search(int pos, int r)
{
    ll sum = 0;
    r = n - r;
    while (pos)
    {
        sum += t[pos];
        sum -= r * t1[pos];
        pos -= lowbit(pos);
    }

    return sum;
}

void update(int pos, int val)
{
    int x = pos;
    while (pos <= n)
    {
        t[pos] += (n - x + 1) * val;
        t1[pos] += val;
        pos += lowbit(pos);
    }
}

void update1(int pos, ll val)
{
    val = val - search(pos, pos) + search(pos - 1,pos);
    int x = pos;
    while (pos <= n)
    {
        t[pos] += (n - x + 1) * val;
        t1[pos] += val;
        pos += lowbit(pos);
    }
}

void init()
{
    memset(t, 0, sizeof(t));
    memset(t1, 0, sizeof(t1));

    for (int i = 1; i <= n; i++)
        update(i, ans[i]);
}

int main()
{
    ios::sync_with_stdio(false);
    cin >> n >> m;

    for (int i = 1; i <= n; i++)
        cin >> ans[i];

    init();

    while (m--)
    {
        int op;
        ll a, b;
        cin >> op >> a >> b;
        if (op == 1)
            cout << search(b, b) - search(a - 1, b) << endl;
        else
            update1(a, b);
    }

    return 0;
}

ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn't want to study

原文地址:https://www.cnblogs.com/qq965921539/p/9623617.html

时间: 2024-11-05 22:04:41

ACM-ICPC 2018徐州网络赛-H题 Ryuji doesn't want to study的相关文章

2018徐州网络赛H. Ryuji doesn&#39;t want to study

题目链接: https://nanti.jisuanke.com/t/31458 题解: 建立两个树状数组,第一个是,a[1]*n+a[2]*(n-1)....+a[n]*1;第二个是正常的a[1],a[2],a[3]...a[n] #include "bits/stdc++.h" using namespace std; #define ll long long const int MAXN=1e5+10; ll sum[MAXN],ans[MAXN]; ll num[MAXN];

2018 徐州网络赛 H

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i]. Unfortunately, the longer he learns, the fewer he gets. That means, if he reads books from ll to rr, he will get a

ACM 2018 南京网络赛H题Set解题报告

题目描述 给定\(n\)个数$a_i$,起初第\(i\)个数在第\(i\)个集合.有三种操作(共\(m\)次): 1 $u$ $v$ 将第$u$个数和第$v$个数所在集合合并 2 $u$ 将第$u$个数所在集合所有数加1 3 $u$ $k$ $x$ 问$u$所在集合有多少个数模$2^k$余$x$. 数据范围:\(n,m \le 500000,a_i \le 10^9, 0 \le k \le 30\). 简要题解 显然此题可以用set加启发式合并在\(O(n \log ^2 n)\)时间复杂度解

ACM-ICPC 2018青岛网络赛-H题

把这题的每个点分成两种情况看,如果是从这个点开始,0算作2,1算作1,如果是中间点或者是结束点,如果和前面的相同看作2,不相同看作1 #include <iostream> #include <string> #include <string.h> using namespace std; int main() { ios::sync_with_stdio(false); int t; cin >> t; while (t--) { int a, b; st

hdu 4438 第37届ACM/ICPC 天津赛区现场赛H题

题意:Alice和Bob两个人去打猎,有两种(只)猎物老虎和狼: 杀死老虎得分x,狼得分y: 如果两个人都选择同样的猎物,则Alice得分的概率是p,则Bob得分的概率是(1-p): 但是Alice事先知道Bob先选老虎的概率是Q,问Alice得分的期望最大值是 求期望 如果先去打老虎,则会有bob先去打狼和bob去打老虎两种情况,期望相加则是alice去打老虎的期望,然后求打狼的期望,比较大小即可 1 #include<cstdio> 2 #include<iostream> 3

2018 徐州网络赛A

262144K After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked Kokoro to deliver a Nogaku show during the feast. To enjoy the show, every audience has to wear a Nogaku mask, and seat around as a circle. There are N guests Re

2018 徐州网络赛 J

131072K After the long vacation, the maze designer master has to do his job. A tour company gives him a map which is a rectangle. The map consists of N \times MN×M little squares. That is to say, the height of the rectangle is NN and the width of the

hdu 4431 第37届ACM/ICPC 天津赛区现场赛A题 枚举

题意:就是给了13张牌.问增加哪些牌可以胡牌.m是数字,s是条,p是筒,c是数字 胡牌有以下几种情况: 1.一个对子 +  4组 3个相同的牌或者顺子.  只有m.s.p是可以构成顺子的.东西南北这样的牌没有顺子. 2.7个不同的对子. 3.1m,9m,1p,9p,1s,9s,1c,2c,3c,4c,5c,6c,7c.  这13种牌每种都有,而且仅有这13种牌.肯定是有一种2张.其他的1张. 模拟即可,第一个对子的情况需要枚举 很麻烦的模拟,但是貌似稳银的很需要这题,所以这种难度必须要弄懂,加油

2017 acm icpc 沈阳(网络赛)5/12 题解

比赛中较...能做的5道题 hdoj6195. cable cable cable 题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=6195 题目大意 : 略 规律 : 答案 = k+(m-k)*k hdoj6198. number number number 题目链接 : http://acm.hdu.edu.cn/showproblem.php?pid=6198 题目大意  : 给你一个整数n.问你n个斐波那契数(可重复)不能构成哪些数,输出