今天做了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,好像有车万的曲子,反正是我今天才听到的