题目链接: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. idea导入ssm项目启动tomcat报错404

    用idea写ssm项目,基于之前一直在用spring boot  对于idea如何运行ssm花费了一番功夫 启动Tom act一直在报404 我搜了网上各种解决办法都不行,花费一天多的时间解决不了 就 ...

  2. MySQL学习笔记之左连接

     MySQL的左连接 #左连接,以左表为基表 select class1.stuid,class1.stuname,sex,course from class1 left join course on ...

  3. javascript执行环境及作用域

    执行环境(execution context,为简单起见,有时也成为“环境”)是javascript中最为重要的一个概念.执行环境定义了变量或函数有权访问的其他数据,决定了它们各自的行为.每个执行环境 ...

  4. python爬虫:找房助手V1.0-爬取58同城租房信息

    1.用于爬取58上的租房信息,限成都,其他地方的,可以把网址改改: 2.这个爬虫有一点问题,就是没用多线程,因为我用了之后总是会报: 'module' object has no attribute ...

  5. SAP computer之RAM

    RAM The RAM is a 16 X 8 static TTL RAM. We can program the RAM by means of the address and data swit ...

  6. dubbo之线程模型

    事件处理线程说明 如果事件处理的逻辑能迅速完成,并且不会发起新的IO请求,比如只是在内存中记个标识,则直接在IO线程上处理更快,因为减少了线程池调度. 但如果事件处理逻辑较慢,或者需要发起新的IO请求 ...

  7. PHP执行Mysql数据库的备份和还原

    使用mysqldump命令备份 mysqldump命令将数据库中的数据备份成一个文本文件.表的结构和表中的数据将存储在生成的文本文件中. mysqldump命令的工作原理很简单.它先查出需要备份的表的 ...

  8. [Intermediate Algorithm] - Arguments Optional

    题目 创建一个计算两个参数之和的 function.如果只有一个参数,则返回一个 function,该 function 请求一个参数然后返回求和的结果. 例如,add(2, 3) 应该返回 5,而 ...

  9. C#遍历/反射 属性/字段

    public static string SortParam<T>(T t) { string tStr = string.Empty; if (t == null) { return s ...

  10. 【转载】JSTL和EL的使用

    使用JSTL前的准备 想要使用JSTL,首先需要给工程导入JSTL的包(JSTL.jar和standard.jar). JSTL标签库 在JSTL中分为以下五个标签 核心标签 格式化标签 SQL标签 ...