玲瓏杯 Round #20
阿新 • • 發佈:2018-12-31
1161 - 康娜的數學課
,l,rx,l,r
意義如上。
OUTPUT
共 nn
行,如果能表示出則輸出“QWQ” (不包括引號),如果不能表示出則輸出"TAT"(不包括引號)
SAMPLE INPUT
15 2 3
SAMPLE OUTPUT
QWQ
HINT
n≤10000n≤100001≤x,l,r≤10181≤x,l,r≤1018
1157 - 造物主的戒律
Time Limit:1s Memory Limit:256MByte
Submissions:615Solved:221
DESCRIPTION
康娜上三年級了,老師要教她一些簡單的算術。出題人:啊,為什麼康娜這麼萌
具體而言,老師總共給了康娜 nn
個問題,每個問題是這樣的~
給你 x,l,rx,l,r
, [l,r][l,r]
以內的每一個數均可以使用任意次,請問你能不能讓他們的和為 xx
這個題實在是太簡單啦,於是康娜一眼就看出來了。
現在康娜把這題拿給了你,你能不能做出來呢?
x一定要在[l,r]的整數倍的所有區間的並集裡面。所以只需要列舉某一區間即可。一除法確定r,一模確定是否在區間內。
#include<bits/stdc++.h> using namespace std; int main(){ int n; scanf("%lld",&n); long long x,l,r,t1,t2; while(n--){ scanf("%lld%lld%lld",&x,&l,&r); t1=t2=0; t1=x/l; t2=x%l; if(t2<=(r-l)*t1)puts("QWQ"); else puts("TAT"); } return 0; }
1157 - 造物主的戒律
Time Limit:20s Memory Limit:512MByte
Submissions:871Solved:109
DESCRIPTION
造物主的戒律,空氣,變成資料結構!
於是空氣變成了資料結構~
給你一個序列,每次查詢區間中小於等於x的所有數字裡面第k1k1小的值以及大於x的所有數字裡面第k2k2小的值,如果不存在,輸出-1
每次輸出兩個數,對於每個數如果不存在,則單獨輸出-1
主席樹詢問區間k小值。對於大於x的第k小數,先查小於等於x的總共有幾個,然後再查這個區間的第x+k小的數。
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400010;
const int M = MAXN * 30;
int n,q,m,tot;
int a[MAXN], t[MAXN];
int T[MAXN], lson[M], rson[M], c[M];
void Init_hash()
{
for(int i = 1; i <= n; i++)
t[i] = a[i];
sort(t+1,t+1+n);
m = unique(t+1,t+1+n)-t-1;
}
int build(int l,int r)
{
int root = tot++;
c[root] = 0;
if(l != r) {
int mid = (l+r)>>1;
lson[root] = build(l,mid);
rson[root] = build(mid+1,r);
}
return root;
}
int update(int root,int pos,int val)
{
int newroot = tot++, tmp = newroot;
c[newroot] = c[root] + val;
int l = 1, r = m;
while(l < r) {
int mid = (l+r)>>1;
if(pos <= mid) {
lson[newroot] = tot++;
rson[newroot] = rson[root];
newroot = lson[newroot];
root = lson[root];
r = mid;
} else {
rson[newroot] = tot++;
lson[newroot] = lson[root];
newroot = rson[newroot];
root = rson[root];
l = mid+1;
}
c[newroot] = c[root] + val;
}
return tmp;
}
int getsum(int left_root,int right_root,int x)
{
if (x==0) return 0;
int l = 1, r = m;
int res = 0;
while( l < r) {
int mid=(l+r)>>1;
if (mid<=x) {
res+=c[lson[left_root]]-c[lson[right_root]];
l=mid+1;
left_root = rson[left_root];
right_root = rson[right_root];
} else {
r=mid;
left_root = lson[left_root];
right_root = lson[right_root];
}
}
return res;
}
int getkth(int left_root,int right_root,int k)
{
int l = 1, r = m;
while( l < r) {
int mid = (l+r)>>1;
if (c[left_root]-c[right_root] < k || k == 0) return -1;
if (c[lson[left_root]]-c[lson[right_root]] >= k ) {
r = mid;
left_root = lson[left_root];
right_root = lson[right_root];
} else {
l = mid + 1;
k -= c[lson[left_root]] - c[lson[right_root]];
left_root = rson[left_root];
right_root = rson[right_root];
}
}
return l;
}
namespace fastIO {
#define BUF_SIZE 10000000
//fread -> read
bool IOerror = 0;
inline char nc() {
static char buf[BUF_SIZE], *p1 = buf + BUF_SIZE, *pend = buf + BUF_SIZE;
if(p1 == pend) {
p1 = buf;
pend = buf + fread(buf, 1, BUF_SIZE, stdin);
if(pend == p1) {
IOerror = 1;
return -1;
}
}
return *p1++;
}
inline bool blank(char ch) {
return ch == ' ' || ch == '\n' || ch == '\r' || ch == '\t';
}
inline void read(int &x) {
char ch;
while(blank(ch = nc()));
if(IOerror)
return;
for(x = ch - '0'; (ch = nc()) >= '0' && ch <= '9'; x = x * 10 + ch - '0');
}
#undef BUF_SIZE
};
int main()
{
using namespace fastIO;
read(n);read(q);
tot = 0;
for (int i = 1; i <= n; i++) {
read(a[i]);
}
Init_hash();
T[n+1] = build(1,m);
for (int i = n; i ; i--) {
int pos = lower_bound(t+1,t+1+m,a[i])-t;
T[i] = update(T[i+1],pos,1);
}
while (q--) {
int l,r,x,k1,k2;
read(l);read(r);read(x);read(k1);read(k2);
x=upper_bound(t+1,t+1+m,x)-t-1;
int s=getsum(T[l],T[r+1],x);
int a=getkth(T[l],T[r+1],k1);
if (a > x) a=-1;
if (a!=-1) a=t[a];
int b=getkth(T[l],T[r+1],s + k2);
if (b!=-1) b=t[b];
printf("%d %d\n",a,b);
}
return 0;
}