ural 1707. Hypnotoad's Secret(线段树)
题目链接:ural 1707. Hypnotoad's Secret
题目大意:给定N和M,然后N组s0, t0, Δs, Δt, k,每组能够计算出k个星星的坐标;M组a0, b0, c0, d0, Δa, Δb, Δc,
Δd, q。每组要求算出q个矩形,推断矩形内是否包括星星,对于q≥20的情况要依据公式计算一个值就可以。
解题思路:计算出全部的星星坐标和矩阵,这个每的说了,将矩阵差分成两点。通过计算出每一个点左下角有多少个星
星,然后用容斥计算出矩阵内是否有点。这个属于线段树的一个应用。
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;
const ll mod = 200904040963LL;
const int maxn = 300000;
#define lson(x) ((x)<<1)
#define rson(x) (((x)<<1)|1)
int lc[maxn << 2], rc[maxn << 2], s[maxn << 2];
inline void pushup(int u) {
s[u] = s[lson(u)] + s[rson(u)];
}
void build (int u, int l, int r) {
lc[u] = l;
rc[u] = r;
s[u] = 0;
if (l == r)
return;
int mid = (l + r) / 2;
build(lson(u), l, mid);
build(rson(u), mid + 1, r);
pushup(u);
}
void modify(int u, int x) {
if (lc[u] == x && x == rc[u]) {
s[u] += 1;
return;
}
int mid = (lc[u] + rc[u]) / 2;
if (x <= mid)
modify(lson(u), x);
else
modify(rson(u), x);
pushup(u);
}
int query(int u, int l, int r) {
if (l <= lc[u] && rc[u] <= r)
return s[u];
int mid = (lc[u] + rc[u]) / 2, ret = 0;
if (l <= mid)
ret += query(lson(u), l, r);
if (r > mid)
ret += query(rson(u), l, r);
return ret;
}
struct point {
int t, x, y;
point (int x = 0, int y = 0, int t = 0) {
set(x, y);
this->t = t;
}
void set (int x, int y) {
this->x = x;
this->y = y;
}
friend bool operator < (const point& a, const point& b) {
if (a.x != b.x)
return a.x < b.x;
if (a.y != b.y)
return a.y < b.y;
return a.t < b.t;
}
};
struct state {
point a, b;
state (point a, point b) {
this->a = a;
this->b = b;
}
};
int N, M, P;
ll T[350];
vector<int> pos, tmp, cnt;
vector<point> vec;
vector<state> que;
map<point, int> G;
inline void add_point (ll x, ll y, int k) {
vec.push_back(point(x, y, k));
tmp.push_back(y);
}
inline void add_state (int a, int b, int c, int d) {
add_point(a - 1, b - 1, 1);
add_point(c, d, 1);
int u = vec.size();
que.push_back(state(vec[u-2], vec[u-1]));
add_point(a - 1, d, 1);
add_point(c, b - 1, 1);
}
inline int find (int a) {
return lower_bound(pos.begin(), pos.end(), a) - pos.begin();
}
void init () {
G.clear();
cnt.clear();
vec.clear();
que.clear();
pos.clear();
tmp.clear();
int a, b, c, d, aa, bb, cc, dd, k;
for (int i = 0; i < M; i++) {
scanf("%d%d%d%d%d", &a, &b, &aa, &bb, &k);
a = (a + N) % N; b = (b + N) % N;
for (int j = 0; j < k; j++) {
add_point(a, b, 0);
a = (a + aa + N) % N;
b = (b + bb + N) % N;
}
}
scanf("%d", &P);
for (int i = 0; i < P; i++) {
scanf("%d%d%d%d", &a, &b, &c, &d);
scanf("%d%d%d%d%d", &aa, &bb, &cc, &dd, &k);
a = (a + N) % N; b = (b + N) % N;
c = (c + N) % N; d = (d + N) % N;
cnt.push_back(k);
for (int j = 0; j < k; j++) {
add_state(min(a, b), min(c, d), max(a, b), max(c, d));
a = (a + aa + N) % N; b = (b + bb + N) % N;
c = (c + cc + N) % N; d = (d + dd + N) % N;
}
}
sort(vec.begin(), vec.end());
sort(tmp.begin(), tmp.end());
pos.push_back(tmp[0]);
for (int i = 1; i < tmp.size(); i++) {
if (tmp[i] != tmp[i-1])
pos.push_back(tmp[i]);
}
build(1, 0, pos.size());
}
inline int judge (state u) {
return G[u.b] + G[u.a] - G[point(u.b.x, u.a.y, 1)] - G[point(u.a.x, u.b.y, 1)];
}
void solve () {
for (int i = 0; i < vec.size(); i++) {
if (vec[i].t)
G[vec[i]] = query(1, 0, find(vec[i].y));
else
modify(1, find(vec[i].y));
}
int mv = 0;
for (int i = 0; i < cnt.size(); i++) {
if (cnt[i] > 20) {
ll ret = 0;
for (int j = 0; j < cnt[i]; j++)
ret = (ret + (judge(que[mv + j]) > 0 ?
1 : 0) * T[j]) % mod;
printf("%lld", ret);
} else {
for (int j = 0; j < cnt[i]; j++)
printf("%d", judge(que[mv + j]) > 0 ?
1 : 0);
}
mv += cnt[i];
printf("\n");
}
}
int main () {
T[0] = 1;
for (int i = 1; i <= 345; i++)
T[i] = T[i-1] * 7 % mod;
while (scanf("%d%d", &N, &M) == 2) {
init();
solve();
}
return 0;
}ural 1707. Hypnotoad's Secret(线段树)的更多相关文章
- URAL 1707. Hypnotoad's Secret(树阵)
URAL 1707. Hypnotoad's Secret space=1&num=1707" target="_blank" style="" ...
- 【URAL 1989】 Subpalindromes(线段树维护哈希)
Description You have a string and queries of two types: replace i'th character of the string by char ...
- Stars(树状数组或线段树)
Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...
- URAL 1890 . Money out of Thin Air (dfs序hash + 线段树)
题目链接: URAL 1890 . Money out of Thin Air 题目描述: 给出一个公司里面上司和下级的附属关系,还有每一个人的工资,然后有两种询问: 1:employee x y z ...
- N - Subpalindromes URAL - 1989 哈希+线段树
N - Subpalindromes URAL - 1989 这个是一个哈希+线段树,这个题目也不算特别难,但是呢,还比较有意思. 这个题目给你两个操作,一个是回答l~r 区间是不是回文,一个是对一个 ...
- URAL 1989 Subpalindromes (多项式hash) +【线段树】
<题目链接> <转载于 >>> > 题目大意:给你一段字符串,进行两种操作:1.询问[l,r]这个区间中的字符串是否是回文串: 2.更改该字符串中对应下标的 ...
- C - K-inversions URAL - 1523 (dp + 线段树)
题目链接:https://cn.vjudge.net/contest/275079#problem/C 具体思路:我们可以分层的去建立,假设我们要找k层,我们可以先把满足1.2....k-1层的满足情 ...
- 【最近公共祖先】【线段树】URAL - 2109 - Tourism on Mars
Few people know, but a long time ago a developed state existed on Mars. It consisted of n cities, nu ...
- URAL 1297 后缀数组+线段树
思路: 论文题--*n 倒过来接上 分奇偶讨论 求LCP 搞棵线段树即可 //By SiriusRen #include <cstdio> #include <cstring> ...
随机推荐
- heap堆&&priority_queue优先队列
堆(heap)不是stl中的东西...它分为 max heap 和min heap. 但我不想用这些,而是采用了priority_queue,优先队列,定义在queue中.顾名思义,它的作用就是无论怎 ...
- ks shell OpenStack 封装
- 包教包会:本地推送 & 远程推送
什么是推送?注意,和我们常用的抽象通知不同(NSNotification): 可以让不在前台运行的app,告知用户app内部发生了什么事情:或者没有运行的app接收到服务器发来的通知..比如离线QQ接 ...
- Python 39 数据库的数据类型
一:整型 为什么需要 数据分类? 1.为了描述事物更加准确 2.描述起来更方便 3.节省内存空间 例:1 a 你 utf8 下 5个字节 1 a b c unicode 6个字节 mysq ...
- Python 34(进程了解)
一:僵尸进程与孤儿进程 测试程序: 基本概念: 一个进程使用fork创建子进程,如果子进程退出,而父进程并没有调用wait或waitpid获取子进程的状态信息,那么子进程的进程描述符仍然保存在系统中. ...
- Redis(四)-配置
Redis 配置 Redis 的配置文件位于 Redis 安装目录下,文件名为 redis.conf. 你可以通过 CONFIG 命令查看或设置配置项. 语法 Redis CONFIG 命令格式如下: ...
- NYOJ999 师傅又被妖怪抓走了
只记得当下的眼疼 , ok 各种数据也试了 , 就是 他娘的不对 , 我也是醉了 . 也是日了最野的狗 附上日了哮天犬的代码 , 这个题 先放放, 一段时间后再试试 , 明天开始状态压缩吧 .为期两天 ...
- BZOJ 3876 有上下界的网络流
思路: 套用有上下界的网络流 就好了 (这算是裸题吧) 比如 有条 x->y 的边 流量上限为R 下限为L 那么du[x]-=L,du[y]+=L 流量上限变成R-L du[x]>0 ...
- 脑洞大开加偏执人格——可持久化treap版的Link Cut Tree
一直没有点动态树这个科技树,因为听说只能用Splay,用Treap的话多一个log.有一天脑洞大开,想到也许Treap也能从底向上Split.仔细思考了一下,发现翻转标记不好写,再仔细思考了一下,发现 ...
- Lambda&Linq
var list = new List<Model> { , UserName = ", Email = "zhang3@yoy.com"}, , UserN ...