2016大连网络赛

1008 Function

题解:如果a>=b,那么a%b<=a/2;

一个数n从本来的位置递减到0最多只需要logn次,也就是往右递减的位置最多不超过30个,那么我们就可以预处理出每个数往右递减的位置,然后离线询问,

用一个优先队列存储数和数所在的位置,比如8 7 6 9 10,先push(8,1)进去,然后每次把队首拿出来,8%7=1,把(1,1)push进去,然后把(8,1)pop出来,(7,2)push进去,优先队列最大值优先,当队首元素小于当前元素的时候,把当前元素和位置push进去,开始枚举下一个数

 1 #include <iostream>
 2 #include <algorithm>
 3 #include <stdio.h>
 4 #include <string.h>
 5 #include <stdlib.h>
 6 #include <queue>
 7 using namespace std;
 8 const int maxn=1e5+10;
 9 struct node
10 {
11     int id;
12     int data;
13     int cnt;
14     friend bool operator < (const node&a,const node&b)
15     {
16         return a.data<b.data;
17     }
18 };
19 struct node2
20 {
21     int pos;
22     int data;
23     void init()
24     {
25         pos=0;
26     }
27 };
28 node a[maxn];
29 node2 pos[maxn][32];
30 priority_queue<node> q;
31 int main()
32 {
33     int T;
34     scanf("%d",&T);
35     while(T--)
36     {
37         while(!q.empty()) q.pop();
38         int n;
39         scanf("%d",&n);
40         for(int i=1;i<=n;i++)
41         {
42             int x;
43             scanf("%d",&x);
44             a[i].data=x;
45             a[i].id=i;
46             a[i].cnt=0;
47             pos[i][0].data=x;
48             pos[i][0].pos=i;
49             for(int j=1;j<=30;j++)
50             {
51                 pos[i][j].init();
52             }
53         }
54         q.push(a[1]);
55         for(int i=2;i<=n;i++)
56         {
57             node tmp;
58             while(q.top().data>=a[i].data)
59             {
60                 tmp=q.top();
61                 q.pop();
62                 tmp.data%=a[i].data;
63                 tmp.cnt+=1;
64                 pos[tmp.id][tmp.cnt].pos=i;
65                 pos[tmp.id][tmp.cnt].data=tmp.data;
66                 q.push(tmp);
67
68             }
69             q.push(a[i]);
70         }
71         int m;
72         scanf("%d",&m);
73         while(m--)
74         {
75             int l,r;
76             int ans;
77             scanf("%d %d",&l,&r);
78             if(l==r){
79                 printf("%d\n",a[l].data);
80                 continue;
81             }
82             else
83             {
84                 for(int i=0;i<=30;i++)
85                 {
86
87                     if(pos[l][i].pos>r||pos[l][i].pos==0) break;
88                     ans=pos[l][i].data;
89                 }
90                 printf("%d\n",ans);
91             }
92         }
93
94     }
95     return 0;
96 }

时间: 2024-08-01 15:41:29

2016大连网络赛的相关文章

2016大连网络赛 1008 &amp; hdu5875 (优先队列+离线)=不确定暴力

题意:给你一个区间,求a_l%a_(l+1)%a_(l+2)%-%a_r 的值 分析:听说一个数在给定区间中只有不是很多的位置可一连续对它求模,所以想到一个比较暴力有可行的方法,猜想复杂度应该是nlogn.具体是这样的,从左到有枚举每个位置, L[]记录[1,r]中所有元素连续取模到r的值.一开始把a[1]加进优先队列pq,对于第二位置,若pq.top()>=a[i],取出并取模,然后更新对应的位置l的答案,并把取模后答案插入优先队列,然后处理有区间是2的所有询问.对于第i个位置,若pq.top

2016大连网络赛 Sparse Graph

Sparse Graph Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem Description In graph theory, the complement of a graph G is a graph H on the same vertices such that two distinct vertices of H are adjacent if

2016大连网络赛 Weak Pair

Weak Pair Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total Submission(s): 333    Accepted Submission(s): 111 Problem Description You are given a rooted tree of N nodes, labeled from 1 to N. To the ith node a

2016大连网络赛 Function

Function Time Limit: 7000/3500 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others) Problem Description The shorter, the simpler. With this problem, you should be convinced of this truth.    You are given an array A of N postive integers,

2016大连网络赛 Different GCD Subarray Query

Different GCD Subarray Query Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description This is a simple problem. The teacher gives Bob a list of problems about GCD (Greatest Common Divisor). After studyin

2016大连网络赛 Football Games

Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description A mysterious country will hold a football world championships---Abnormal Cup, attracting football teams and fans from all around th

大连网络赛 1006 Football Games

1 //大连网络赛 1006 2 // 吐槽:数据比较水.下面代码可以AC 3 // 但是正解好像是:排序后,前i项的和大于等于i*(i-1) 4 5 #include <bits/stdc++.h> 6 using namespace std; 7 #define LL long long 8 typedef pair<int,int> pii; 9 const double inf = 123456789012345.0; 10 const LL MOD =100000000L

2016 CCPC 网络赛 B 高斯消元 C 树形dp(待补) G 状压dp+容斥(待补) H 计算几何

2016 CCPC 网络赛 A - A water problem 水题,但读题有个坑,输入数字长度很大.. B - Zhu and 772002 题意:给出n个数(给出的每个数的质因子最大不超过2000),选出多个数相乘得b.问有多少种选法让b 为完全平方数. tags:高斯消元,求异或方程组解的个数.   好题 每个数先素数分解开.  对于2000以内的每个素数p[i],这n个数有奇数个p[i]则系数为1,偶数个则系数为0,最后n个数的p[i]系数异或和都要为0才会使得最后的积为完全平方数.

HDU 5880 Family View (2016 青岛网络赛 C题,AC自动机)

题目链接  2016 青岛网络赛  Problem C 题意  给出一些敏感词,和一篇文章.现在要屏蔽这篇文章中所有出现过的敏感词,屏蔽掉的用$'*'$表示. 建立$AC$自动机,查询的时候沿着$fail$指针往下走,当匹配成功的时候更新$f[i]$ $f[i]$表示要屏蔽以第$i$个字母结尾的长度为$f[i]$的字符串. 原文地址:https://www.cnblogs.com/cxhscst2/p/8452147.html