题目链接: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(线段树)的更多相关文章

  1. URAL 1707. Hypnotoad&#39;s Secret(树阵)

    URAL 1707. Hypnotoad's Secret space=1&num=1707" target="_blank" style="" ...

  2. 【URAL 1989】 Subpalindromes(线段树维护哈希)

    Description You have a string and queries of two types: replace i'th character of the string by char ...

  3. Stars(树状数组或线段树)

    Stars Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 37323 Accepted: 16278 Description A ...

  4. URAL 1890 . Money out of Thin Air (dfs序hash + 线段树)

    题目链接: URAL 1890 . Money out of Thin Air 题目描述: 给出一个公司里面上司和下级的附属关系,还有每一个人的工资,然后有两种询问: 1:employee x y z ...

  5. N - Subpalindromes URAL - 1989 哈希+线段树

    N - Subpalindromes URAL - 1989 这个是一个哈希+线段树,这个题目也不算特别难,但是呢,还比较有意思. 这个题目给你两个操作,一个是回答l~r 区间是不是回文,一个是对一个 ...

  6. URAL 1989 Subpalindromes (多项式hash) +【线段树】

    <题目链接> <转载于 >>>  > 题目大意:给你一段字符串,进行两种操作:1.询问[l,r]这个区间中的字符串是否是回文串: 2.更改该字符串中对应下标的 ...

  7. C - K-inversions URAL - 1523 (dp + 线段树)

    题目链接:https://cn.vjudge.net/contest/275079#problem/C 具体思路:我们可以分层的去建立,假设我们要找k层,我们可以先把满足1.2....k-1层的满足情 ...

  8. 【最近公共祖先】【线段树】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 ...

  9. URAL 1297 后缀数组+线段树

    思路: 论文题--*n 倒过来接上 分奇偶讨论 求LCP 搞棵线段树即可 //By SiriusRen #include <cstdio> #include <cstring> ...

随机推荐

  1. K-means (PRML) in C++

    原始数据 #include <iostream>#include <fstream>#include <sstream>#include <vector> ...

  2. PCB LDI文件 自动化输出(改造)实现思路

    由于工厂采用Liunxs系统输出LDI文件,由于我们数据库是用的Windows Server,编程语言是.net 无法与Liunxs系统进行有效对接, 所以造成才会造成LDI 资料输效率极低,人员工作 ...

  3. ecshop数据库说明

    数据库 ecshop 表的结构 ecs_account_log 字段 类型 空 默认 含义 log_id mediumint(8) 否 账户记录表 user_id mediumint(8) 否 用户编 ...

  4. Spring Cloud (1) 服务的注册与发现(Eureka)

    Spring Cloud简介 Spring Cloud是一个基于Spring Boot实现的云应用开发工具,它为基于JVM的云应用开发中涉及的配置管理.服务发现.断路器.智能路由.微代理.控制总线.全 ...

  5. Excel的用到的常规的技巧

    这几天在做各种发票的报表,好几百的数据当然离不开EXCel,自己又是个白班,就记录下啦! EXCEL 判断某一单元格值是否包含在某一列中 就在Excel的表格中加入这个函数:=IF(ISERROR(V ...

  6. mysqlslap对mysql进行压力测试

    mysqlslap是从5.1.4版开始的一个MySQL官方提供的压力测试工具.通过模拟多个并发客户端访问MySQL来执行压力测试,并且能很好的对比多个存储引擎在相同环境下的并发压力性能差别. mysq ...

  7. C# 增加 删除 更新 方法

    /// <summary> /// 增加一条数据 /// </summary> public int Add(string 表名,string 参数,string 参数值) { ...

  8. Jenkins 定时 构建项目

    选择要定时构建的 项目-->配置-->构建触发器 触发项目: Poll SCM:定时检查源码变更(根据SCM软件的版本号),如果有更新就checkout最新code下来,然后执行构建动作. ...

  9. mysql 是如何保证在高并发的情况下autoincrement关键字修饰的列不会出现重复

    转载自 https://juejin.im/book/5bffcbc9f265da614b11b731/section/5c42cf94e51d45524861122d#heading-8 mysql ...

  10. 25-Ubuntu-文件和目录命令-其他命令-重定向

    重定向 Linux允许将命令执行结果重定向到一个文件. 将本应显示到终端上的内容输出或追加到指定文件中. 重定向命令 含义 > 表示输出,会覆盖原有文件. >> 表示追加,会将内容追 ...