Solution

注意到$\gcd$具有结合律:

\[
\gcd(a, b, c) = \gcd(a, \gcd(b, c))
\]

因此我们从后往前, 对于每个位置$L$, 找到每一段不同的$\gcd(a_x, a_{x + 1}, \cdots, a_R)$. 我们注意到这样的$R$最多只有$\log$段.

每个位置合并其后面一个位置的信息.

同时我们还维护序列的前缀异或和, 对于每个异或值, 都开一颗线段树来存储其出现的位置. 随便乱搞即可.

#include <cstdio>
#include <cctype>
#include <vector>
#include <algorithm>
#include <map> typedef long long LL;
using namespace std;
namespace Zeonfai
{
inline LL getLL()
{
LL a = 0, sgn = 1; char c;
while (! isdigit(c = getchar())) if (c == '-') sgn *= -1;
while (isdigit(c)) a = a * 10 + c - '0', c = getchar();
return a * sgn;
}
}
const int N = (int)1e5, INF = (int)2e9;
int n;
LL a[N + 1], sum[N + 1];
struct record
{
int ed; LL val;
inline record(int _ed, LL _val) { ed = _ed; val = _val; }
};
vector<record> bck[N + 1];
map<LL, int> mp;
struct segmentTree
{
struct node
{
node *suc[2];
inline node() { for (int i = 0; i < 2; ++ i) suc[i] = NULL; }
}*rt;
inline segmentTree() { rt = NULL; }
node *insert(node *u, int L, int R, int pos)
{
if (u == NULL) u = new node;
if (L == R) return u;
if (pos <= L + R >> 1) u->suc[0] = insert(u->suc[0], L, L + R >> 1, pos);
else u->suc[1] = insert(u->suc[1], (L + R >> 1) + 1, R, pos);
return u;
}
inline void insert(int pos) { rt = insert(rt, 1, n, pos); }
int find(node *u, int curL, int curR, int L, int R)
{
if (u == NULL) return INF;
if (curL == curR) return curL;
int res = INF, mid = curL + curR >> 1;
if (L <= mid) res = min(res, find(u->suc[0], curL, mid, L, R));
if (res == INF && R > mid) res = min(res, find(u->suc[1], mid + 1, curR, L, R));
return res;
}
inline int find(int L, int R) { return find(rt, 1, n, L, R); }
}seg[N];
/* inline LL __gcd(LL a, LL b)
{
if (a < b) swap(a, b);
while (b)
{
LL tmp = b;
b = a % b;
a = tmp;
}
return a;
} */
inline vector<record>::iterator getPrevious(vector<record>::iterator p) { return -- p; }
int main()
{ #ifndef ONLINE_JUDGE freopen("start.in", "r", stdin);
freopen("start.out", "w", stdout); #endif using namespace Zeonfai;
n = getLL();
for (int i = 1; i <= n; ++ i) a[i] = getLL();
for (int i = n; i; -- i)
{
bck[i].push_back(record(i, a[i])); int tot = 1;
if (i != n)
{
for (vector<record>::iterator p = bck[i + 1].begin(); p != bck[i + 1].end(); ++ p)
if (__gcd(p->val, a[i]) != bck[i][tot - 1].val)
bck[i].push_back(record(p->ed, __gcd(a[i], p->val))), ++ tot;
else bck[i][tot - 1].ed = p->ed;
}
}
sum[0] = 0; mp.clear(); int tot = 0;
for (int i = 1; i <= n; ++ i)
{
sum[i] = sum[i - 1] ^ a[i];
if (mp.find(sum[i]) == mp.end()) mp[sum[i]] = tot ++;
seg[mp[sum[i]]].insert(i);
}
LL K = getLL();
for (int i = 1; i <= n; ++ i)
{
for (vector<record>::iterator p = bck[i].begin(); p != bck[i].end(); ++ p)
{
if (K % p->val) continue;
int res = INF;
if (mp.find(K / p->val ^ sum[i - 1]) != mp.end())
res = seg[mp[K / p->val ^ sum[i - 1]]].find(p == bck[i].begin() ? i : getPrevious(p)->ed + 1, p->ed);
if (res != INF)
{
printf("%d %d\n", i, res);
return 0;
}
}
}
puts("no solution");
}

NOI模拟题5 Problem A: 开场题的更多相关文章

  1. fzuoj Problem 2182 水题

    http://acm.fzu.edu.cn/problem.php?pid=2182 Problem 2182 水题 Accept: 188    Submit: 277Time Limit: 100 ...

  2. 【NOIP2017提高A组模拟9.7】JZOJ 计数题

    [NOIP2017提高A组模拟9.7]JZOJ 计数题 题目 Description Input Output Sample Input 5 2 2 3 4 5 Sample Output 8 6 D ...

  3. noip模拟9 达哥随单题

    T1.随 看题第一眼,就瞄到最下面 孙金宁教你学数学  ?????原根?目测神题,果断跳过. 最后打了个快速幂,愉快的收到了达哥送来的10分. 实际上这题暴力不难想,看到一个非常小的mod应该就能想到 ...

  4. 5.23 NOI 模拟

    $5.23\ NOI $模拟 \(T1\)简单的计算几何题 \(zjr:\)我当时没改,那么自己看题解吧 倒是有个简单的随机化方法(能获得\(72pts,\)正确性未知)\(:\) 随机两条切椭圆的平 ...

  5. 【2018.12.10】NOI模拟赛3

    题目 WZJ题解 大概就是全场就我写不过 $FFT$ 系列吧……自闭 T1 奶一口,下次再写不出这种 $NTT$ 裸题题目我就艹了自己 -_-||| 而且这跟我口胡的自创模拟题 $set1$ 的 $T ...

  6. LCT题单(自己的做题情况反馈)(转自Flash)

    LCT题单(自己的做题情况反馈)(转自Flash) 随时进Flash Hu的LCT看一发 也可以看一下我自己的风格的板子 开始 维护链信息(LCT上的平衡树操作) [X] 洛谷P3690 [模板]Li ...

  7. NOI模拟赛Day3

    终于A题啦鼓掌~开心~ 开考看完题后,觉得第二题很好捏(傻叉上线 搞到十一点准备弃疗了然后突然发现我会做第一题 于是瞎码了码,就去准备饭票了... 好了,停止扯淡(就我一个我妹子每天不说话好难受QAQ ...

  8. 经典算法题每日演练——第十七题 Dijkstra算法

    原文:经典算法题每日演练--第十七题 Dijkstra算法 或许在生活中,经常会碰到针对某一个问题,在众多的限制条件下,如何去寻找一个最优解?可能大家想到了很多诸如“线性规划”,“动态规划” 这些经典 ...

  9. 经典算法题每日演练——第十一题 Bitmap算法

    原文:经典算法题每日演练--第十一题 Bitmap算法 在所有具有性能优化的数据结构中,我想大家使用最多的就是hash表,是的,在具有定位查找上具有O(1)的常量时间,多么的简洁优美, 但是在特定的场 ...

随机推荐

  1. 1717: [Usaco2006 Dec]Milk Patterns 产奶的模式

    1717: [Usaco2006 Dec]Milk Patterns 产奶的模式 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1469  Solved: ...

  2. Redis实现之对象(三)

    集合对象 集合对象的编码可以是intset或者hashtable,intset编码的集合对象使用整数集合作为底层实现,集合对象包含的所有元素都被保存在整数集合里面.举个栗子,以下代码将创建一个图1-1 ...

  3. tomcat内存泄漏存入dump文件

    很多tomcat进程退出(或者进程假死),都是由于频繁的抛出OutOfMemeoryError导致的. 为了让tomcat退出前或者发生OutOfMemeoryError时自动dump堆栈信息,方便事 ...

  4. 快速获取Android应用包名和Activity名

    一.获取包名 方法1: 先说明一下这里讲的方法是通用的,而网上其他方法获取PackageName不通用(因为他是建立在root的基础上的,我不敢保证你的设备已经root). ①在android设备上点 ...

  5. [c++基础]3/5原则--拷贝构造函数+拷贝赋值操作符

    /* * main.cpp * * Created on: Apr 7, 2016 * Author: lizhen */ #include <iostream> #include &qu ...

  6. 利用js生成二维码

    $('#barcode').qrcode({ width: 300, height: 300, render: !!document.createElement('canvas').getContex ...

  7. 关于Android应用中图片占用内存浅谈

    从事过移动端应用开发的童鞋应该都清楚,内存是非常宝贵的资源.如果能很好的利用有限的内存,对应用性能的提升会有很大的帮助.在实际应用开发中图片内存占整个应用非常大的比重,我们只有了解图片是如何加载到内存 ...

  8. 【bzoj3435】[Wc2014]紫荆花之恋 替罪点分树套SBT

    题目描述 强强和萌萌是一对好朋友.有一天他们在外面闲逛,突然看到前方有一棵紫荆树.这已经是紫荆花飞舞的季节了,无数的花瓣以肉眼可见的速度从紫荆树上长了出来.仔细看看的话,这个大树实际上是一个带权树.每 ...

  9. 【bzoj2242】[SDOI2011]计算器 EXgcd+BSGS

    题目描述 你被要求设计一个计算器完成以下三项任务: 1.给定y,z,p,计算Y^Z Mod P 的值: 2.给定y,z,p,计算满足xy≡ Z ( mod P )的最小非负整数: 3.给定y,z,p, ...

  10. [SDOI2011][bzoj2286] 消耗战 [虚树+dp]

    题面: 传送门 思路: 看到所有询问中的点数总和是十万级别的,就想到用虚树~\(≧▽≦)/~啦 首先,树形dp应该是很明显可以看出来的: 设dp[u]表示以u为根的子树(不包括u)中的宝藏岛全部切断的 ...