这套月赛题不是特别难

T1:离散化+单调队列,队列里出现数的种类不超过K+1,找最大的num[a[i]]

T2:一眼可以看出BFS+状压DP,还要SPFA预处理出各个块之间的dis

T3:线段树,没什么难度

 #include<stdio.h>
 #include<string.h>
 #include<algorithm>
 using namespace std;
 ;
 int n,K,a[maxn],b[maxn],m,ans,head,tail,q[maxn],vis[maxn],cnt;
 int main(){
     scanf("%d%d", &n, &K);
     ; i<=n; i++) scanf("%d", &b[i]),a[i]=b[i];
     sort(b+,b++n);
     m=unique(b+,b++n)-b-;
     ; i<=n; i++) a[i]=lower_bound(b+,b++m,a[i])-b;
     //for (int i=1; i<=n; i++) printf("%d\n", a[i]);
     head=tail=cnt=;
     ; i<=n; i++){
         if (!vis[a[i]]) cnt++;
         vis[a[i]]++; q[tail++]=i;
         ){
             vis[a[q[head]]]--; ) cnt--;
             head++;
         }
         ans=max(ans,vis[a[q[tail-]]]);
     }
     printf("%d\n", ans);
     ;
 }
 #include<stdio.h>
 #include<string.h>
 #include<algorithm>
 #include<queue>
 using namespace std;
 ;
 ]={,,,-};
 ]={,-,,};
 struct node{
     int x,y;
     node(int _x, int _y):x(_x),y(_y){}
 };
 <<][],dis[][],id[maxn][maxn],vis[maxn][maxn],cnt,stx[],sty[],N;
 char s[maxn][maxn];

 bool check(int x, int y){
      || y< || x>n || y>m) ; ;
 }

 void bfs(int sx, int sy, int num){
     queue<node> Q;
     Q.push(node(sx,sy)); id[sx][sy]=num;
     vis[sx][sy]=;
     while (!Q.empty()){
         int x=Q.front().x, y=Q.front().y; Q.pop();
         ; k<; k++){
             int tx=x+dx[k], ty=y+dy[k];
             if (check(tx,ty) && !vis[tx][ty] && s[tx][ty]=='X'){
                 vis[tx][ty]=; id[tx][ty]=num;
                 Q.push(node(tx,ty));
             }
         }
     }
 }

 void find_land(){
     cnt=;
     ; i<=n; i++)
         ; j<=m; j++)
             if (s[i][j]=='X' && !vis[i][j]){
                 bfs(i,j,++cnt);
                 stx[cnt]=i; sty[cnt]=j;
             }
 //    for (int i=1; i<=cnt; i++) printf("  %d %d\n", stx[i], sty[i]);
 }

 void spfa(int sx, int sy, int num){
     queue<node> Q;
     int next,cost; memset(d,0x3f,sizeof(d));
     memset(dis[num],0x3f,sizeof(dis[num]));
     Q.push(node(sx,sy)); d[sx][sy]=; vis[sx][sy]=; dis[num][num]=;
     while (!Q.empty()){
         int x=Q.front().x, y=Q.front().y; Q.pop();
         ; k<; k++){
             int tx=x+dx[k], ty=y+dy[k];
             if (!check(tx,ty) || s[tx][ty]=='.') continue;
             cost=(s[tx][ty]=='S');
             if (d[tx][ty]>d[x][y]+cost){
                 d[tx][ty]=d[x][y]+cost;
                 ){
                     vis[tx][ty]=;
                     Q.push(node(tx,ty));
                 }
             }
             if ((s[tx][ty]=='X') && ((next=id[tx][ty])!=num)) dis[num][next]=min(dis[num][next],d[tx][ty]);
         }
         vis[x][y]=;
     }
 }

 void dp(){
     N=(<<cnt);
     memset(f,0x3f,sizeof(f));
     ; i<=cnt; i++) f[(<<(i-))][i]=;
     ; s<N; s++){
         ; i<=cnt; i++) <<(i-)))
             ; j<=cnt; j++) <<(j-))))
                 f[s^(<<(j-))][j]=min(f[s^(<<(j-))][j],f[s][i]+dis[i][j]);
     }
     int ans=0x7fffffff;
     ; i<=cnt; i++) ans=min(ans,f[N-][i]);
     printf("%d\n", ans);
 }

 int main(){
     scanf("%d%d", &n, &m);
     ; i<=n; i++){
         scanf();
     }
     find_land();
     ; i<=cnt; i++)
         spfa(stx[i],sty[i],i);
     dp();
     ;
 }
 #include<stdio.h>
 #include<string.h>
 #include<algorithm>
 using namespace std;
 ;
 struct node{
     int l,r,len,lz,lm,rm,mx;
 }t[maxn*],now;
 int n,m,x,y,ans;
 ];

 void pushup(int x){
     t[x].lm=t[x<<].lm;
     ].lm==t[x<<].len) t[x].lm=t[x<<].len+t[x<<|].lm;
     t[x].rm=t[x<<|].rm;
     |].rm==t[x<<|].len) t[x].rm=t[x<<|].len+t[x<<].rm;
     t[x].mx=max(t[x<<].rm+t[x<<|].lm,max(t[x<<].mx,t[x<<|].mx));
 }

 void pushdown(int x){
     ){  //涂色
         t[x<<].lz=; t[x<<|].lz=;
         t[x<<].lm=t[x<<].rm=t[x<<].mx=;
         t[x<<|].lm=t[x<<|].rm=t[x<<|].mx=;
     }
     ){ //不涂色
         t[x<<].lz=; t[x<<|].lz=;
         t[x<<].lm=t[x<<].rm=t[x<<].mx=t[x<<].len;
         t[x<<|].lm=t[x<<|].rm=t[x<<|].mx=t[x<<|].len;
     }
     t[x].lz=;
 }

 node query(int x, int p){
     int l=t[x].l, r=t[x].r;
     pushdown(x);
     ].mx>=p) ,p);
     ].rm+t[x<<|].lm>=p){
         node ret;
         ret.l=t[x<<].r-t[x<<].rm+;
         ret.r=ret.l+p-;
         return ret;
     }|,p);
 }

 void update(int a, int b, int x, int c){
     int l=t[x].l, r=t[x].r;
     if (l==a && r==b){
         ){
             t[x].lz=;
             t[x].lm=t[x].rm=t[x].mx=;
         }
         ){
             t[x].lz=;
             t[x].lm=t[x].rm=t[x].mx=t[x].len;
         }
         return;
     }
     ;
     pushdown(x);
     ,c);
     |,c);
     ,c),update(mid+,b,x<<|,c);
     pushup(x);
 }

 void build(int l, int r, int x){
     t[x].l=l; t[x].r=r; t[x].len=r-l+;
     if (l==r){
         t[x].lz=; t[x].lm=t[x].rm=t[x].mx=;
         return;
     }
     ;
     build(l,mid,x<<);
     build(mid+,r,x<<|);
     pushup(x);
 }

 int main(){
     scanf("%d%d", &n, &m);
     build(,n,);
     //printf("%d\n", t[1].mx);
     while (m--){
         scanf("%s", opt);
         ]=='A'){
             scanf("%d", &x);
             ].mx<x) ans++;
             else{
                 now=query(,x);
                 //printf(" %d %d\n", now.l, now.r);
                 update(now.l,now.r,,);
             }
         }else{
             scanf("%d%d", &x, &y);
             update(x,y,,);
         }
     }
     printf("%d\n", ans);
     ;
 } 

bzoj3048+3049+3050的更多相关文章

  1. Bzoj索引

    1001 : http://ideone.com/4omPYJ1002 : http://ideone.com/BZr9KF1003 : http://ideone.com/48NJNh1004 : ...

  2. Hsql中In没有1000的限制

    SELECT * FROM user , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ...

  3. 存储过程数据insert into select

    create or replace procedure PRO_K3_CZZH (org_name in varchar2, --财政专户名称 opertype in varchar2, --操作类型 ...

  4. jqu

    1 /*2 * 说明:3 * 本源代码的中文注释乃Auscarlin呕心沥血所作.旨在促进jQuery的传播以及向广大jQuery爱好者提供一个进阶4 *的途径,以让各位更加深入地了解jQuery,学 ...

  5. 7.12归来赛_B

    Prime Judge 时间限制 1000 ms 内存限制 65536 KB 题目描写叙述 众所周知.假设一个正整数仅仅能被1和自身整除,那么该数被称为素数.题目的任务非常easy.就是判定一个数是否 ...

  6. 【8.0.0_r4】AMS分析(十六)(ActivityManagerService.java上)

    代码位于frameworks/base/services/core/java/com/android/server/am/,一共有七十个文件. Java源码位于package com.android. ...

  7. POJ -3050 Hopscotch

    http://poj.org/problem?id=3050 给定一个5×5矩阵,问选6个数的不同排列总数是多少! 二维的搜索,注意要判重,数据量很小,直接用map就好. #include<cs ...

  8. hdu - 3049 - Data Processing(乘法逆元)

    题意:N(N<=40000)个数n1, n2, ..., nN (ni<=N),求(2 ^ n1 + 2 ^ n2 + ... + 2 ^nN) / N % 1000003. 题目链接:h ...

  9. LOJ 3049: 洛谷 P5284: 「十二省联考 2019」字符串问题

    题目传送门:LOJ #3049. 题意简述: 给定一个长度为 \(n\) 的母串 \(S\). 有 \(n_a\) 个 A 类串,都是 \(S\) 的子串,以区间的形式给出. 有 \(n_b\) 个 ...

随机推荐

  1. 利用html5、websocket和opencv实现人脸检测

    最近学习人脸识别相关的东西,在MFC下使用OpenCV做了一个简单的应用.训练需要较多的数据,windows应用程序终究还是不方便,于是想着做成CS模式:检测识别都放在服务器端,视频获取和显示都放在网 ...

  2. RakNet发送与接收数据

    http://www.jenkinssoftware.com/raknet/manual/creatingpackets.html Creating Packets with Bitstreams W ...

  3. 如何下架app

    因赶数日工期成,偷得浮生半日闲.遂登录iTunes Connect,发现之前做过的小程序,想将其下架,故而有此篇随想.(温馨提示:项目被下架后再次上架该版本,不需要再次经过审核)下面是详情步骤: 1. ...

  4. 给DOM生成的元素添加事件

    问题:通过js给页面添加新元素,并给该元素添加绑定事件,但新添加的元素上却没有绑定任何事件. 常见例子:在处理表格的时候,每行行末有个删除按钮,如下图.点击删除按钮的时候删除这一行. //html部分 ...

  5. C# 小知识

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.C ...

  6. python import cv2 出错:cv2.x86_64-linux-gnu.so: undefined symbol

    之前写过一个python使用opencv处理图片的脚本,当时是可以使用的,现在突然发现执行时出错: ImportError: /usr/lib/python2.7/dist-packages/cv2. ...

  7. POCO库——Foundation组件之核心Core

    核心Core: Version.h:版本控制信息,宏POCO_VERSION,值格式采用0xAABBCCDD,分别代表主版本.次版本.补丁版本.预发布版本: Poco.h:简单地包含了头文件Found ...

  8. JDBC URL FOR ORACLE, wrong or correct, how do you know? ORA-12505

    JDBC URL FOR ORACLE, wrong or correct, how do you know? INSTANCE SID by ":" jdbc:oracle:th ...

  9. git 查看某文件的修改历史

    前提 先进入此文件所在的目录下 1. git log filename可以看到fileName相关的commit记录2. git log -p filename可以显示每次提交的diff3. 只看某次 ...

  10. 关于SVN出现 svn working copy locked的原因及解决方法

    今天使用SVN时电脑卡住了,于是结束进程中断了SVN的操作,于是出现了如题问题, 产生这种情况大多是因为上次svn更新命令执行失败且被自动锁定了. 如果cleanup没有效果的话只好手动删除锁定文件. ...