从左往右扫,找到比第i个小的第一个数字,l[i] = l[last] + (i - last) * m[i],用单调栈O(n)维护这个过程,再从右往左扫,同理可以算出r数组,注意一下long long #include <bits/stdc++.h> using namespace std; ; int m[N], ans[N]; long long l[N], r[N]; stack < int > s; int main() { int n; scanf("%d&qu…
链接: https://codeforces.com/contest/1185/problem/C2 题意: The only difference between easy and hard versions is constraints. If you write a solution in Python, then prefer to send it in PyPy to speed up execution time. A session has begun at Beland Stat…
A: 题意: 有ABC的三种菜,现在有a个A,b个B,c个C,问能组成多少种不同菜单 思路: abc都大于等于4,肯定是7种,给abc排个序,从大到小举例删减 #include<bits/stdc++.h> using namespace std; #define ll long long #define il inline #define it register int #define inf 0x3f3f3f3f #define lowbit(x) (x)&(-x) #define…
B. Different Rules Nikolay has only recently started in competitive programming, but already qualified to the finals of one prestigious olympiad. There going to be n participants, one of whom is Nikolay. Like any good olympiad, it consists of two rou…
This is an easier version of the problem. In this version n≤1000n≤1000 The outskirts of the capital are being actively built up in Berland. The company "Kernel Panic" manages the construction of a residential complex of skyscrapers in New Berlsk…
Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made aa portions of dumplings, bb portions of cranberry juice and cc pancakes with condensed milk. The peculiarity of Denis's restaurant is the procedure o…
C1. Skyscrapers (easy version) time limit per test1 second memory limit per test512 megabytes inputstandard input outputstandard output This is an easier version of the problem. In this version n≤1000 The outskirts of the capital are being actively b…
Tired of boring office work, Denis decided to open a fast food restaurant. On the first day he made a portions of dumplings, b portions of cranberry juice and c pancakes with condensed milk. The peculiarity of Denis's restaurant is the procedure of o…
题意:给你两个长度为\(n\)的01串\(s\)和\(t\),可以选择\(s\)的前几位,取反然后反转,保证\(s\)总能通过不超过\(2n\)的操作得到\(t\),输出变换总数,和每次变换的位置. 题解:我们现将\(s\)串全部变成\(1\)或\(0\),确保\(s[n]=t[n]\),然后我们倒着遍历\(t\),若遇到相邻的两个字符不同,我们就对\(s\)中相应的位置执行一次操作,然后继续遍历,如下图: 代码: int t; int n; char s[N],tmp[N]; vector<i…
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate it n = int(raw_input()) s = "" a = ["I hate that ","I love that ", "I hate it","I love it"] for i in ran…
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/output 1 s, 256 MB x3384 B Pyramid of Glasses standard input/output 1 s, 256 MB x1462 C Vasya and String standard input/output 1 s, 256 MB x1393…