当前位置:网站首页>Codeforces Round #645 (Div. 2)
Codeforces Round #645 (Div. 2)
2022-06-29 10:10:00 【It's mally!】
Codeforces Round #645 (Div. 2)
Notes :
Official explanation :https://codeforces.com/blog/entry/77869
C Problem thinking
D Problem thinking , The use of inference can be skillfully solved by circulation ( You can also use binary trees )
C. Celex Update
Category : thinking

Observation reveals ,
Go all the way down , And then to the right , And will be the largest .
Change the right step to the down step each time , The sum can be added 1.
Above description sum The value of is increasing , And the incremental value is 1.
So if you know sum Maximum and minimum of , You can know how many sum.

So if you know that there is n That's ok m Column ,
Then the difference is
( 0 + n − 1 ) ∗ n + ( n − 1 ) ∗ ( m − n − 1 ) = n ∗ m − n − m + 1 (0+n-1)*n+ (n-1)*(m-n-1)=n*m-n-m+1 (0+n−1)∗n+(n−1)∗(m−n−1)=n∗m−n−m+1
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main()
{
int cas;
scanf("%d",&cas);
ll x1,y1,x2,y2;
while(cas--)
{
cin>>x1>>y1>>x2>>y2;
ll n=x2-x1+1;
ll m=y2-y1+1;
ll ans=n*m-n-m+1+1;
cout<<ans<<endl;
}
return 0;
}C+=
D. The Best Vacation
Category : thinking , Use inference to solve ( You can also use binary trees )
subject : Yes n Months , Everyone with a a_i God , The daily value is i, Select consecutive x God , bring sum Maximum .
Answer key :
1. Use inference : The last day of every consecutive day must be the last day of that month ,
prove : If not , Suppose this last day is a i x a_{ix} aix, So moving forward is a i ( x + 1 ) a_{i(x+1)} ai(x+1), that sum It can only be less than or equal to the previous one sum, So the biggest sum Only on the last day .
2. Because it can not be in the same year , That is, the array can loop , So double the length of the array .
#include <iostream>
#include <algorithm>
#include <vector>
#define int long long
using namespace std;
signed main() {
freopen("in.text","r",stdin);
int n, len;
cin >> n >> len;
vector<int> A(2 * n); // It is used to record the days of each month
for (int i = 0; i < n; i++) {
cin >> A[i];
A[n + i] = A[i];
}
n *= 2;
vector<int> B = {0}, C = {0}; //B It is used to record the cumulative sum of days ,C Used to record the cumulative sum of values
for (int i = 0; i < n; i++)
B.push_back(B.back() + A[i]);
for (int i = 0; i < n; i++) {
C.push_back(C.back() + (A[i] * (A[i] + 1)) / 2);
}
int ans = 0;
for (int i = 0; i < n; i++) {
if (B[i + 1] >= len) {
int z = upper_bound(B.begin(), B.end(), B[i + 1] - len) - B.begin();
int cnt = C[i + 1] - C[z];
int days = B[i + 1] - B[z];
int too = len - days;
cnt += ((A[z - 1] * (A[z - 1] + 1)) / 2);
cnt -= (((A[z - 1] - too) * (A[z - 1] - too + 1)) / 2);
ans = max(ans, cnt);
}
}
cout << ans;
}
边栏推荐
- 基辅周边的凄美废墟——切尔诺贝利的安全前往指南!
- Wechat applet implements the data listener watch, including the watch that destroys the watch and sub attributes
- Middle order traversal of Li Kou 94 binary tree
- Is flush stock trading software reliable and safe?
- 任务调度器之Azkaban的使用
- 自定义控件之下载控件1(DownloadView1)
- gcc与makefile
- The Stones Game【取石子博弈 & 思维】
- Introduction to intranet penetration tool FRP
- Caused by: org.apache.xerces.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8
猜你喜欢
随机推荐
Caused by: org.apache.xerces.impl.io.MalformedByteSequenceException: Invalid byte 3 of 3-byte UTF-8
GCC and makefile
Setinterval, setTimeout and requestanimationframe
阿里云服务器安装配置redis,无法远程访问
Using rancher to build kubernetes cluster
GridView of basic component of shutter
Force deduction 85 question maximum rectangle
聊聊你理解的线程与并发
Codeforces Round #645 (Div. 2)
Community Union
HDU 6778 Car (分组枚举-->状压 dp)
JVM之对象的内存布局
Symphony tutorial
gSoap例子——calc
Binding mechanism of JVM methods
Generic paging framework
Zabbix4.4 configure the indicators of the monitoring server and solve the garbled graphics pages
Custom MVC framework implementation
Cisco ASA、FTD和HyperFlex HX的漏洞分析复现
A 3D Dual Path U-Net of Cancer Segmentation Based on MRI







