Educational Codeforces Round 80 (Rated for Div. 2)E(树状数组,模拟,思维)

 1 #define HAVE_STRUCT_TIMESPEC
 2 #include<bits/stdc++.h>
 3 using namespace std;
 4 int mn[600007],mx[600007],a[600007],pos[600007],sum[600007];
 5 int n,m;
 6 int lowbit(int x){
 7     return x&(-x);
 8 }
 9 void add(int x,int val){//单点更新
10     while(x<600007){
11         sum[x]+=val;
12         x+=lowbit(x);
13     }
14 }
15 int ask(int x){//区间查询[1~n]的和
16     int res=0;
17     while(x){
18         res+=sum[x];
19         x-=lowbit(x);
20     }
21     return res;
22 }
23 int main(){
24     ios::sync_with_stdio(false);
25     cin.tie(NULL);
26     cout.tie(NULL);
27     cin>>n>>m;
28     for(int i=1;i<=n;++i){
29         mn[i]=mx[i]=i;//初始最前最后都是i
30         pos[i]=i+m;//前面预留m个位置以便插入
31         add(pos[i],1);//当前位置有人了,所以给当前位置+1
32     }
33     for(int i=0;i<m;++i){
34         cin>>a[i];
35         mn[a[i]]=1;//它的最前更新为1
36         int p=a[i];
37         mx[p]=max(mx[p],ask(pos[p]));//更新最大值,是否更新为它之前位置前面有多少个数字(空位置不算,贡献是0)
38         add(pos[p],-1);//原来位置没有了
39         pos[p]=m-i;//新位置
40         add(pos[p],1);//数字换到了现在的位置上
41     }
42     for(int i=1;i<=n;++i)
43         mx[i]=max(mx[i],ask(pos[i]));//更新最大值,是否更新为它之前位置前面有多少个数字(空位置不算,贡献是0)
44     for(int i=1;i<=n;++i)
45         cout<<mn[i]<<‘ ‘<<mx[i]<<‘\n‘;
46     return 0;
47 }

原文地址:https://www.cnblogs.com/ldudxy/p/12203364.html

时间: 2024-08-30 01:36:10

Educational Codeforces Round 80 (Rated for Div. 2)E(树状数组,模拟,思维)的相关文章

Educational Codeforces Round 80 (Rated for Div. 2)

\[Educational\ Codeforces\ Round\ 80\ (Rated\ for\ Div.\ 2)\] A.Deadline 打勾函数找最小值,在\(\sqrt{d}\)邻域里找\(x\)最小化\(x+\lceil\frac{d}{x+1}\rceil\)即可 //#pragma comment(linker, "/STACK:1024000000,1024000000") #include<bits/stdc++.h> using namespace

Educational Codeforces Round 80 (Rated for Div. 2)(C - Two Arrays )

C - Two Arrays 题目链接:https://codeforces.com/contest/1288/problem/C 题目: 题意:给你n,m,利用1~n之间的数(可重复)来组成长度为m的数组a,b,要求数组a非递减,数组b非递增,且a数组的数<=b数组中的数,求出a,b数组对数 思路:用动态规划,dp[i][j]是第i个位置放数字j的方案数,根据题意可以将b数组反置然后接在a后面,则该数组长度为2m,为一个非递减序列,则就是求1~n这些数字可重复组成多少种长度为2m的非递减序列,

Educational Codeforces Round 80 (Rated for Div. 2)参加感悟

这次比赛有14000+的人报名,结果我得了266名,创了新纪录. 进过这次比赛,我有回答了1800+. 寒假到了,又可以每次比赛都打了.平时进步很慢,我希望能在寒假有更大的进步. 作为寒假第一场比赛,发挥让我还是很满意的. 开始讲题: A: http://codeforces.com/contest/1288/problem/A 这题太水了,直接是sqrt(d)-1和sqrt(d),如果它们不行,那么其他的也肯定不行. 直接上代码: 1 #include<bits/stdc++.h> 2 #d

Educational Codeforces Round 80 (Rated for Div. 2(A Deadline )

(A) Deadline 题目: 思路:一开始还傻傻的暴力康康....只要求出令x=n的一半就行,然后判断 1 #include<bits/stdc++.h> 2 using namespace std; 3 int main() 4 { 5 //freopen("text","r",stdin); 6 int T; 7 scanf("%d",&T); 8 while(T--) 9 { 10 //cout<<cei

题解 Educational Codeforces Round 80 [Rated for Div. 2](CF1288)

前言:11点的时候某天下第一可爱的萌神问我怎么不打CF,跑去开题,11:30终于开了C和D,秒了一下,考后萌神轻松上分并告诉我E的tag于是我赛后补题. A:n/x上取整是(n-1)/x+1,式子变形成x+1+(n-1)/(x+1)<=d.根据a+b>=2√ab随便化简一下.(20s秒了??) 1 #include<stdio.h> 2 #include<math.h> 3 using namespace std; 4 int T,n,d,x,y; 5 int main

Educational Codeforces Round 80 (Rated for Div. 2) C - Two Arrays(DP)

???♀? ???♀? ???♀? 题意:从1~n里面选出来m个数字组成a数组,再选出来m个组成b数组,要求a非递减,b非递增,且bi>=ai 1,说是选两个数组其实就是选出来一个长m*2的非递减数组 2,假设要从n的全排列中选出来m长的非递减数组,因为元素是可重复的,最多重复m次,其实就是相当于从下面这个矩阵中选择元素 从这个矩阵中选择元素,每行只能选择一个,枚举我们选出的k个元素的最小值为[ i , j ]位置,那么除去这个元素选择k-1个元素的方案数之和就是k个元素,如图中红色标出位置,最

Educational Codeforces Round 80 (Rated for Div. 2)C(DP)

1 #define HAVE_STRUCT_TIMESPEC 2 #include<bits/stdc++.h> 3 using namespace std; 4 const long long mod = 1e9+7; 5 long long pre[1007][1007],temp[1007][1007]; 6 int main(){ 7 ios::sync_with_stdio(false); 8 cin.tie(NULL); 9 cout.tie(NULL); 10 int n,m;

Educational Codeforces Round 80 (Rated for Div. 2)部分题解

A. Deadline 题目链接 题目大意 给你\(n,d\)两个数,问是否存在\(x\)使得\(x+\frac{d}{x+1}\leq n\),其中\(\frac{d}{x+1}\)向上取整. 解题思路 方案一:利用均值不等式公式推导 \(x+\frac{d}{x+1}=x+1+\frac{d}{x+1}-1\geq2\sqrt{d}-1\) 所以 \(\min(x+\frac{x}{d+1})=2\sqrt{d}-1\) 因此去判断\(2\sqrt{d}-1\leq n\)是否成,即\(4\

Educational Codeforces Round 80 (Rated for Div. 2)【A,B,C,D】C题DP{GG了} D题【数组转化成二进制形式判断+二分】

A题直接暴力水过 1 #include<bits/stdc++.h> 2 3 using namespace std; 4 #define int long long 5 #define N 6666666 6 int arr[N]; 7 8 signed main(){ 9 int _;cin>>_; 10 while(_--){ 11 int n,m; 12 cin>>n>>m; 13 if(n>=m){ 14 cout<<"

Educational Codeforces Round 80 (Rated for Div. 2) 题解

Deadline Yet Another Meme Problem Two Arrays Minimax Problem Messenger Simulator Deadline \[ Time Limit: 2 s\quad Memory Limit: 256 MB \] 这是个对勾函数,所以最小的话是在 \(sqrt\) 位置,所以只要找这附近的数字就可以了. view /************************************************************