【CF】310 Div.1 C. Case of Chocolate
2024-09-08 23:59:53
线段树的简单题目,做一个离散化,O(lgn)可以找到id。RE了一晚上,额,后来找到了原因。
/* 555C */
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <deque>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <cctype>
#include <cassert>
#include <functional>
#include <iterator>
#include <iomanip>
using namespace std;
//#pragma comment(linker,"/STACK:102400000,1024000") #define sti set<int>
#define stpii set<pair<int, int> >
#define mpii map<int,int>
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define rep(i, a, n) for (int i=a;i<n;++i)
#define per(i, a, n) for (int i=n-1;i>=a;--i)
#define clr clear
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define lson l, mid, rt<<1
#define rson mid+1, r, rt<<1|1 typedef struct {
int x, y;
char op[];
} node_t; const int maxn = 2e5+;
const int maxm = 4e5+;
node_t Q[maxn];
int rn[maxm];
int mxr[maxm<<];
int mxc[maxm<<];
int rL[maxm<<];
int cT[maxm<<];
int L, R; void build(int l, int r, int rt) {
rL[rt] = ;
cT[rt] = ;
if (l == r)
return ; int mid = (l+r)>>;
build(lson);
build(rson);
} inline void PushDownR(int rt) {
int lb = rt<<;
int rb = lb | ; if (mxr[rt]) {
rL[rt] = max(rL[rt], mxr[rt]);
mxr[lb] = max(mxr[lb], mxr[rt]);
mxr[rb] = max(mxr[rb], mxr[rt]);
mxr[rt] = ;
}
} inline void PushDownC(int rt) {
int lb = rt<<;
int rb = lb | ; if (mxc[rt]) {
cT[rt] = max(cT[rt], mxc[rt]);
mxc[lb] = max(mxc[lb], mxc[rt]);
mxc[rb] = max(mxc[rb], mxc[rt]);
mxc[rt] = ;
}
} inline void PushDown(int rt) {
int lb = rt<<;
int rb = lb | ; if (mxr[rt]) {
rL[rt] = max(rL[rt], mxr[rt]);
mxr[lb] = max(mxr[lb], mxr[rt]);
mxr[rb] = max(mxr[rb], mxr[rt]);
mxr[rt] = ;
} if (mxc[rt]) {
cT[rt] = max(cT[rt], mxc[rt]);
mxc[lb] = max(mxc[lb], mxc[rt]);
mxc[rb] = max(mxc[rb], mxc[rt]);
mxc[rt] = ;
}
} void updateR(int delta, int l, int r, int rt) {
if (L<=l && R>=r) {
mxr[rt] = max(mxr[rt], delta);
return ;
} int mid = (l+r)>>; PushDownR(rt);
if (mid >= R) {
updateR(delta, lson);
} else if (mid < L) {
updateR(delta, rson);
} else {
updateR(delta, lson);
updateR(delta, rson);
}
} void updateC(int delta, int l, int r, int rt) {
if (L<=l && R>=r) {
mxc[rt] = max(mxc[rt], delta);
return ;
} int mid = (l+r)>>; PushDownC(rt);
if (mid >= R) {
updateC(delta, lson);
} else if (mid < L) {
updateC(delta, rson);
} else {
updateC(delta, lson);
updateC(delta, rson);
}
} pii query(int l, int r, int rt) {
if (l == r) {
rL[rt] = max(rL[rt], mxr[rt]);
cT[rt] = max(cT[rt], mxc[rt]);
mxr[rt] = ;
mxc[rt] = ; pii p(rL[rt], cT[rt]);
return p;
}
int mid = (l+r)>>; PushDown(rt);
if (mid >= R) {
return query(lson);
} else {
return query(rson);
}
} int main() {
ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("data.in", "r", stdin);
freopen("data.out", "w", stdout);
#endif int n, q;
mpii tb;
sti st; scanf("%d %d", &n, &q);
rep(i, , q) {
scanf("%d %d %s", &Q[i].y, &Q[i].x, Q[i].op);
st.insert(Q[i].x);
st.insert(Q[i].y);
}
st.insert(); int m = ;
int i, j, k; for (sti::iterator siter=st.begin(); siter!=st.end(); ++siter) {
k = *siter;
++m;
rn[m] = k;
tb[k] = m;
} int x, y, idx, idy;
int ans;
pii p; build(, m, );
rep(i, , q) {
x = Q[i].x;
y = Q[i].y;
if (Q[i].op[] == 'U') {
idy = tb[y];
L = R = idy;
p = query(, m, );
updateC(x+, , m, );
ans = x - p.sec + ;
idx = tb[x];
k = lower_bound(rn+, rn++m, p.sec) - rn;
L = k;
R = idx;
if (L <= R)
updateR(y+, , m, );
} else {
idx = tb[x];
L = R = idx;
p = query(, m, );
updateR(y+, , m, );
ans = y - p.fir + ;
idy = tb[y];
k = lower_bound(rn+, rn++m, p.fir) - rn;
L = k;
R = idy;
if (L <= R)
updateC(x+, , m, );
}
#ifndef ONLINE_JUDGE
printf("L = %d, R = %d\n", L, R);
#endif
if (ans < )
ans = ;
printf("%d\n", ans);
} #ifndef ONLINE_JUDGE
printf("time = %d.\n", (int)clock());
#endif return ;
}
最新文章
- Redis 学习笔记(C#)
- IIS 7 的 500 內部錯誤
- Js-动态控制table的tr、td增加及删除的具体实现
- [MacOS NSAlert的使用]
- coocs2d-x资源压缩笔记
- MAC OS Finder 中快速定位指定路径
- 原型模式--prototype
- linux 5.5 开xmanager远程
- 4.1Reduction模型
- mybatis04 根据用户名称模糊查询用户信息
- Solr Dataimport配置
- UVa 231 - Testing the CATCHER
- [ZJOI2015]地震后的幻想乡
- Zookeeper的安装部署
- synchronized关键字简介 多线程中篇(十一)
- [转载]深入理解JavaScript系列 --汤姆大叔
- 浅析 Bag of Feature
- 20155323刘威良 网络对抗 Exp2 后门原理与实践
- Fedora23 chrome 安装
- postman—环境切换和设置变量
热门文章
- A题笔记(12)
- ArcGIS Runtime SDK for WPF已不更新,后续将被ArcGIS Runtime SDK for .NET取代
- javaScript笔记1
- scrapy, 自带命令行调用工具.
- 大数据基础知识:分布式计算、服务器集群[zz]
- Codevs 5056 潜水员
- 锋利的Jquery解惑系列(三)------ 各路选择器大聚会
- VI一个终端编辑多个文件的命令
- hadoop1中hdfs原理详解
- Mvvm Light Toolkit for WPF/Silverlight系列之搭建mvvmlight开发框架