每日一枯20220907

今天做了0题,幼儿园斜率优化两个小时没整出来,直到最后之前都用的是没有用到斜率的临时想的假斜率优化

https://codeforc.es/problemset/problem/1715/E

这个代码是WA的,明天再改,今天先撤了

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<LL,int> PLI;
const int N=2e5+5;
int n,m,K;
struct Node
{
    int v,w;
};
vector<Node> g[N];
LL dis[N];
int vi[N];
void dij()
{
    priority_queue<PLI,vector<PLI>,greater<PLI> > Q;
    for(int i=1;i<=n;++i) vi[i]=0,Q.push(PLI(dis[i],i));
    while(!Q.empty())
    {
        int u=Q.top().second; Q.pop();
        if(vi[u]) continue;
//        printf("u=%d\n",u); printf(">>%d\n",g[u].size());
        vi[u]=1;
        for(auto p:g[u])
        {
//            printf("v=%d w=%d\n",p.v,p.w);
            if(dis[p.v]>dis[u]+p.w)
            {
                dis[p.v]=dis[u]+p.w;
                Q.push(PLI(dis[p.v],p.v));
            }
        }
    }
//puts("dij:");for(int i=1;i<=n;++i) printf("%lld ",dis[i]); puts("");
}
void hop()
{
    static PLI Q[N];
    static LL tmp[N];
    int l,r,i;
    auto F=[&](PLI p) { return p.first-2ll*i*p.second; };
    auto KK=[&](PLI a,PLI b) { return (F(b)-F(a))/(b.second-a.second); };
    for(i=1;i<=n;++i) tmp[i]=dis[i];
    
    
    l=1,r=1; Q[1]=PLI(tmp[1]+1,1);
    for(i=2;i<=n;++i)
    {
        PLI u=PLI(tmp[i]+1ll*i*i,i);
        while(r-1>l&&KK(Q[r-1],u)<=KK(Q[r-1],Q[r])) --r;
        Q[++r]=u;
        while(l<r&&F(Q[l])>=F(Q[l+1])) ++l;
        dis[i]=min(dis[i],Q[l].first-2ll*i*Q[l].second+1ll*i*i);
    }
    
    l=r=1; Q[1]=PLI(tmp[n]+1ll*n*n,n);
    for(i=n-1;i;--i)
    {
        PLI u=PLI(tmp[i]+1ll*i*i,i);
        while(r-1>l&&KK(Q[r-1],u)<=KK(Q[r-1],Q[r])) --r;
        Q[++r]=u;
        while(l<r&&F(Q[l])>=F(Q[l+1])) ++l;
        dis[i]=min(dis[i],Q[l].first-2ll*i*Q[l].second+1ll*i*i);
    }
    
//puts("hop:");for(int i=1;i<=n;++i) printf("%lld ",dis[i]); puts("");
}
            
int main()
{
    scanf("%d%d%d",&n,&m,&K);
    for(int i=1;i<=n;++i) dis[i]=1e18; dis[1]=0;
    for(int i=1;i<=m;++i)
    {
        int u,v,w;
        scanf("%d%d%d",&u,&v,&w);
        g[u].push_back((Node) {v,w});
        g[v].push_back((Node) {u,w});
    }
    dij();
    for(int k=1;k<=K;++k)
    {
        hop();
        dij();
    }
    for(int i=1;i<=n;++i) printf("%lld ",dis[i]); puts("");
}

还有昨天的一题忘贴了

https://codeforc.es/contest/1718/problem/C

题意有点长,差不多就是有一个program,可以选择起始位置和步长,在数组上跳n次计算这n个位置值的和,给出修改数组q次,每次修改后问program能得到的最大值。
解法:每次修改后暴力对n的所有质因数p,n/p步长进行维护即可
C. Tonya and Burenka-179
time limit per test3 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard output
Tonya was given an array of a of length n written on a postcard for his birthday. For some reason, the postcard turned out to be a cyclic array, so the index of the element located strictly to the right of the n-th is 1. Tonya wanted to study it better, so he bought a robot “Burenka-179”.

A program for Burenka is a pair of numbers (s,k), where 1≤s≤n, 1≤k≤n−1. Note that k cannot be equal to n. Initially, Tonya puts the robot in the position of the array s. After that, Burenka makes exactly n steps through the array. If at the beginning of a step Burenka stands in the position i, then the following happens:

The number ai is added to the usefulness of the program.
“Burenka” moves k positions to the right (i:=i+k is executed, if i becomes greater than n, then i:=i−n).
Help Tonya find the maximum possible usefulness of a program for “Burenka” if the initial usefulness of any program is 0.

Also, Tony’s friend Ilyusha asks him to change the array q times. Each time he wants to assign ap:=x for a given index p and a value x. You need to find the maximum possible usefulness of the program after each of these changes.

Input
The first line contains a single integer t (1≤t≤104) is the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers n and q (2≤n≤2⋅105, 0≤q≤2⋅105).

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109) — elements of the array.

The following q lines contain changes, each of them contains two integers p and x (1≤p≤n, 1≤x≤109), meaning you should assign ap:=x.

It is guaranteed that the sum of n and the sum of q over all test cases do not exceed 2⋅105.

Output
For each test case, output q+1 numbers — the maximum usefulness of a program initially and after each of the changes.

Example
inputCopy
4
2 1
1 2
1 3
4 4
4 1 3 2
2 6
4 6
1 1
3 11
9 3
1 7 9 4 5 2 3 6 8
3 1
2 1
9 1
6 3
1 1 1 1 1 1
1 5
4 4
3 8
outputCopy
3
5
14
16
24
24
24
57
54
36
36
6
18
27
28
Note
In the first test case, initially and after each request, the answer is achieved at s=1, k=1 or s=2, k=1.

In the second test case, initially, the answer is achieved when s=1, k=2 or s=3, k=2. After the first request, the answer is achieved at s=2, k=2 or s=4, k=2.


随便贴个同人社团:DDBY,好像有车万的曲子,反正是我今天才听到的

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
"Python每日一学"是一个提供每天学习一个Python知识点的系列文章。这个系列包含多个主题,比如切片、回文字符串、回文素数等。其中,切片是一种用于获取列表、字符串、元组等序列对象的子集的方法。切片的语法是s[start:end:step],可以根据需要指定起始位置、结束位置和步长来获取子集。回文字符串是指正着读和反着读都一样的字符串。可以使用切片方法将字符串反转,并与原字符串进行比较,如果相同则是回文字符串。回文素数是同时满足回文和素数条件的数,即既是回文数又是素数。可以通过判断一个数是否既是回文数又是素数来确定是否为回文素数。"Python每日一学"系列中还包含其他主题,比如输出成绩、提取身份号码中的日期与性别等。在输出成绩的例子中,通过判断一个数是否既是回文数又是素数来输出小于给定数的回文素数。总之,"Python每日一学"是一个帮助学习者每天学习一个Python知识点的系列文章,涵盖了多个主题和实例。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [Python每日一学 07——切片](https://blog.csdn.net/qq_52417436/article/details/128112888)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值