[hdu5204]水题

思路:插入的数按指数级增长,所以范围内最多存在logR个数。并且最近i次插入的数,首位置为2^(i-1),且每隔2^i出现一次,于是暴力之。。可以用插入排序维护,也可查询时在排下序。

一:

  1 #pragma comment(linker, "/STACK:10240000,10240000")
  2
  3 #include <iostream>
  4 #include <cstdio>
  5 #include <algorithm>
  6 #include <cstdlib>
  7 #include <cstring>
  8 #include <map>
  9 #include <queue>
 10 #include <deque>
 11 #include <cmath>
 12 #include <vector>
 13 #include <ctime>
 14 #include <cctype>
 15 #include <set>
 16 #include <bitset>
 17 #include <functional>
 18 #include <numeric>
 19 #include <stdexcept>
 20 #include <utility>
 21
 22 using namespace std;
 23
 24 #define mem0(a) memset(a, 0, sizeof(a))
 25 #define lson l, m, rt << 1
 26 #define rson m + 1, r, rt << 1 | 1
 27 #define define_m int m = (l + r) >> 1
 28 #define rep0(a, b) for (int a = 0; a < (b); a++)
 29 #define rep1(a, b) for (int a = 1; a <= (b); a++)
 30 #define all(a) (a).begin(), (a).end()
 31 #define lowbit(x) ((x) & (-(x)))
 32 #define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
 33 #define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
 34 #define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
 35 #define pchr(a) putchar(a)
 36 #define pstr(a) printf("%s", a)
 37 #define sint(a) ReadInt(a)
 38 #define sint2(a, b) ReadInt(a);ReadInt(b)
 39 #define sint3(a, b, c) ReadInt(a);ReadInt(b);ReadInt(c)
 40 #define pint(a) WriteInt(a)
 41
 42 typedef double db;
 43 typedef long long LL;
 44 typedef pair<int, int> pii;
 45 typedef multiset<int> msi;
 46 typedef set<int> si;
 47 typedef vector<int> vi;
 48 typedef map<int, int> mii;
 49
 50 const int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 51 const int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
 52 const int maxn = 1e3 + 7;
 53 const int maxm = 1e5 + 7;
 54 const int maxv = 1e7 + 7;
 55 const int max_val = 1e6 + 7;
 56 const int MD = 1e9 +7;
 57 const int INF = 1e9 + 7;
 58 const double PI = acos(-1.0);
 59 const double eps = 1e-10;
 60
 61 template<class T>T gcd(T a, T b){return b==0?a:gcd(b,a%b);}
 62 template<class T>void ReadInt(T &x){char c=getchar();while(!isdigit(c))c=getchar();x=0;while(isdigit(c)){x=x*10+c-‘0‘;c=getchar();}}
 63 template<class T>void WriteInt(T i) {int p=0;static int b[20];if(i == 0) b[p++] = 0;else while(i){b[p++]=i%10;i/=10;}for(int j=p-1;j>=0;j--)pchr(‘0‘+b[j]);}
 64
 65
 66 struct abc {
 67     pii a[100007];
 68     int l, r;
 69     void Init() { l = r = 0; }
 70     void push_back(int x) {
 71         a[r++] = make_pair(x, 0);
 72         for(int i = l; i < r - 1; i++) a[i].second++;
 73         if (r - l >= 62) {
 74             int pos;
 75             for (int i = l; i < r; i++) {
 76                 if (a[i].second == 61) {
 77                     pos = i;
 78                     break;
 79                 }
 80             }
 81             for (int i = pos; i > l; i--) a[i] = a[i - 1];
 82             l++;
 83         }
 84         int p = r - 1;
 85         while (p > l && a[p].first < a[p - 1].first) {
 86             swap(a[p], a[p - 1]);
 87             p--;
 88         }
 89     }
 90     pii &operator [] (int i) {
 91         return a[l + i];
 92     }
 93     int size() {
 94         return r - l;
 95     }
 96 };
 97
 98
 99 abc g;
100
101 LL calc(LL x, LL pos) {
102     if (x < pos) return 0;
103     return (x - pos) / pos / 2 + 1;
104 }
105 int main() {
106     //freopen("in.txt", "r", stdin);
107     int n;
108     while (cin >> n) {
109         g.Init();
110         rep0(i, n) {
111             int id, w;
112             sint(id);
113             if (id == 1) {
114                 sint(w);
115                 g.push_back(w);
116             }
117             else {
118                 LL L, R, k;
119                 sint3(L, R, k);
120                 int sz = g.size();
121                 rep0(i, sz) {
122                     LL pos = 1LL << g[i].second, c = calc(R, pos) - calc(L - 1, pos);
123                     if (k <= c) {
124                         pint(g[i].first);
125                         pchr(‘\n‘);
126                         break;
127                     }
128                     k -= c;
129                 }
130             }
131         }
132     }
133     return 0;
134 }

二:

  1 #pragma comment(linker, "/STACK:10240000,10240000")
  2
  3 #include <iostream>
  4 #include <cstdio>
  5 #include <algorithm>
  6 #include <cstdlib>
  7 #include <cstring>
  8 #include <map>
  9 #include <queue>
 10 #include <deque>
 11 #include <cmath>
 12 #include <vector>
 13 #include <ctime>
 14 #include <cctype>
 15 #include <set>
 16
 17 using namespace std;
 18
 19 #define mem0(a) memset(a, 0, sizeof(a))
 20 #define lson l, m, rt << 1
 21 #define rson m + 1, r, rt << 1 | 1
 22 #define define_m int m = (l + r) >> 1
 23 #define rep0(a, b) for (int a = 0; a < (b); a++)
 24 #define rep1(a, b) for (int a = 1; a <= (b); a++)
 25 #define all(a) (a).begin(), (a).end()
 26 #define lowbit(x) ((x) & (-(x)))
 27 #define constructInt4(name, a, b, c, d) name(int a = 0, int b = 0, int c = 0, int d = 0): a(a), b(b), c(c), d(d) {}
 28 #define constructInt3(name, a, b, c) name(int a = 0, int b = 0, int c = 0): a(a), b(b), c(c) {}
 29 #define constructInt2(name, a, b) name(int a = 0, int b = 0): a(a), b(b) {}
 30 #define pchr(a) putchar(a)
 31 #define pstr(a) printf("%s", a)
 32 #define sint(a) ReadInt(a)
 33 #define sint2(a, b) ReadInt(a);ReadInt(b)
 34 #define sint3(a, b, c) ReadInt(a);ReadInt(b);ReadInt(c)
 35 #define pint(a) WriteInt(a)
 36
 37 typedef double db;
 38 typedef long long LL;
 39 typedef pair<int, int> pii;
 40 typedef multiset<int> msi;
 41 typedef set<int> si;
 42 typedef vector<int> vi;
 43 typedef map<int, int> mii;
 44
 45 const int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
 46 const int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
 47 const int maxn = 1e3 + 7;
 48 const int maxm = 1e5 + 7;
 49 const int maxv = 1e7 + 7;
 50 const int max_val = 1e6 + 7;
 51 const int MD = 1e9 +7;
 52 const int INF = 1e9 + 7;
 53 const double PI = acos(-1.0);
 54 const double eps = 1e-10;
 55
 56 template<class T>T gcd(T a, T b){return b==0?a:gcd(b,a%b);}
 57 template<class T>void ReadInt(T &x){char c=getchar();while(!isdigit(c))c=getchar();x=0;while(isdigit(c)){x=x*10+c-‘0‘;c=getchar();}}
 58 template<class T>void WriteInt(T i) {int p=0;static int b[20];if(i == 0) b[p++] = 0;else while(i){b[p++]=i%10;i/=10;}for(int j=p-1;j>=0;j--)pchr(‘0‘+b[j]);}
 59
 60 struct abc {
 61     int a[110000];
 62     int l, r;
 63     void Init() { l = r = 0; }
 64     void push_back(int x) {
 65         a[r++] = x;
 66         if (r - l >= 62) {
 67             l++;
 68         }
 69     }
 70     int &operator [] (int i) {
 71         return a[l + i];
 72     }
 73     int size() {
 74         return r - l;
 75     }
 76 };
 77
 78 abc g;
 79
 80 pair<int, LL> a[100];
 81
 82 LL calc(LL x, int id) {
 83     LL start = 1LL << (g.size() - id - 1), t = 1LL << (g.size() - id);
 84     if (x < start) return 0;
 85     return (x - start) / t + 1;
 86 }
 87
 88 int main() {
 89     //freopen("in.txt", "r", stdin);
 90     int n;
 91     while (cin >> n) {
 92         g.Init();
 93         rep0(i, n) {
 94             int id, w;
 95             sint(id);
 96             if (id == 1) {
 97                 sint(w);
 98                 g.push_back(w);
 99             }
100             else {
101                 LL L, R, k;
102                 sint3(L, R, k);
103                 int total = 0, sz = g.size();
104                 rep0(i, sz) {
105                     LL c = calc(R, i) - calc(L - 1, i);
106                     if (c > 0) a[total++] = make_pair(g[i], c);
107                 }
108                 sort(a, a + total);
109                 int now = 0;
110                 while (1) {
111                     if (k <= a[now].second) {
112                         break;
113                     }
114                     k -= a[now++].second;
115                 }
116                 pint(a[now].first);
117                 pchr(‘\n‘);
118             }
119         }
120     }
121     return 0;
122 }

时间: 2024-10-25 06:12:56

[hdu5204]水题的相关文章

2015南阳CCPC L - Huatuo&#39;s Medicine 水题

L - Huatuo's Medicine Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 无 Description Huatuo was a famous doctor. He use identical bottles to carry the medicine. There are different types of medicine. Huatuo put medicines into the bottles and chain these b

sdut 2841 Bit Problem (水题)

题目 贴这个题是因为看题解有更简单的方法, 我做的时候是直接算的, 也很简单. 贴一下题解吧: 如果一个整数不等于 0,那么该整数的二进制表示中至少有一位是 1. 这个题结果可以直接输出 x - (x&(x-1)); 因为x-1 之后二进制下,就是最右边的1变成了0, 最右边的1的 右边所有的0变成了1, 不影响最左边. 我的代码: 1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4

sdut 2413:n a^o7 !(第三届山东省省赛原题,水题,字符串处理)

n a^o7 ! Time Limit: 1000MS Memory limit: 65536K 题目描述 All brave and intelligent fighters, next you will step into a distinctive battleground which is full of sweet and happiness. If you want to win the battle, you must do warm-up according to my inst

杭电(hdu)2053 Switch Game 水题

Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 13113    Accepted Submission(s): 7970 Problem Description There are many lamps in a line. All of them are off at first. A series of o

4.7-4.9补题+水题+高维前缀和

题目链接:51nod 1718 Cos的多项式  [数学] 题解: 2cosx=2cosx 2cos2x=(2cosx)^2-2 2cos3x=(2cosx)^3-3*(2cosx) 数归证明2cos(nx)能表示成关于2cosx的多项式,设为f(n) f(1)=x,f(2)=x^2-2(其中的x就是2cosx) 假设n=1~k时均成立(k>=3) 当n=k+1时 由cos((k+1)x)=cos(kx)cos(x)-sin(kx)sin(x) cos((k-1)x)=cos(kx)cos(x)

历年NOIP水题泛做

快noip了就乱做一下历年的noip题目咯.. noip2014 飞扬的小鸟 其实这道题并不是很难,但是就有点难搞 听说男神错了一个小时.. 就是$f_{i,j}$表示在第$i$个位置高度为$j$的时候最小点击次数 递推的话对于上升的情况只做一次,后面几次在后面再做.. #include <cstdio> #include <cstring> #include <cstdlib> #include <algorithm> using namespace st

[ZPG TEST 114] 阿狸的英文名【水题】

1.      阿狸的英文名 阿狸最近想起一个英文名,于是他在网上查了很多个名字.他发现一些名字可以由两个不同的名字各取一部分得来,例如John(约翰)的前缀 "John"和Robinson(鲁滨逊)的后缀 "son" 连在一起就是Johnson. 现在他找到了两个喜欢的名字(名字可看作字符串),用A和B表示,他想知道取A的一个非空前缀和B的一个非空后缀,连接在一起能组成多少不同的字符串. 输入格式 输入两行,分别表示字符串A和B:字符串只包含小写英文字母. 输出格

G - Brain Network (easy)(并查集水题)

G - Brain Network (easy) Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u CodeForces 690C1 Description One particularly well-known fact about zombies is that they move and think terribly slowly. While we still don't know

UVaLive 6591 &amp;&amp; Gym 100299L Bus (水题)

题意:略. 析:不解释,水题. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set>