[swustoj 1021] Submissions of online judge
Submissions of online judge(1021)
问题描述
输入
The first line is an integer T (1 ≤ T ≤ 10), which stands for the number of test cases you need to solve. For each case, the input format will be like this
Line 1: N (1 ≤ N ≤ 100,000) indicating the number of submissions.
Line 2: N integers U1, U2…UN (0 ≤ Ui ≤ 1000,000,000). Ui indicates the User ID of the i-th (Run ID) submission.( For the sake of simplicity, User ID is digital)
Line 3: Q (1 ≤ Q ≤ 100,000), the number of Queries.
Next Q lines: each line contains 2 integers L, R representing a Query (1 ≤ L ≤ R ≤ N). Interval contains the endpoint.
输出
For each Query, print the number of different Users from L to R in one line.
样例输入
样例输出
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <map>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
#define N 100010 struct Query{
int id;
int l,r;
int ans;
}q[N]; int n,m;
int a[N];
int cnt[N<<];
map<int,int> mp; bool cmp1(const Query &q1,const Query &q2){return q1.r<q2.r;}
bool cmp2(const Query &q1,const Query &q2){return q1.id<q2.id;} void pushup(int rt)
{
cnt[rt]=cnt[rt<<]+cnt[rt<<|];
}
void update(int l,int r,int rt,int pos,int c)
{
if(l==r){
cnt[rt]=c;
return;
}
int m=(l+r)>>;
if(pos<=m) update(l,m,rt<<,pos,c);
else update(m+,r,rt<<|,pos,c);
pushup(rt);
}
int query(int l,int r,int rt,int L,int R)
{
if(l==L && r==R){
return cnt[rt];
}
int m=(l+r)>>;
if(R<=m) return query(l,m,rt<<,L,R);
else if(L>m) return query(m+,r,rt<<|,L,R);
else return query(l,m,rt<<,L,m)+query(m+,r,rt<<|,m+,R);
}
int main()
{
int T;
int i,j;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
mp.clear();
memset(cnt,,sizeof(cnt));
for(i=;i<=n;i++) scanf("%d",&a[i]);
scanf("%d",&m);
for(i=;i<=m;i++){
scanf("%d%d",&q[i].l,&q[i].r);
q[i].id=i;
}
sort(q+,q+m+,cmp1);
i=,j=;
while(j<=m){
for(;i<=q[j].r;i++){
int t=mp[a[i]];
if(!t){
update(,n,,i,);
mp[a[i]]=i;
}
else{
update(,n,,t,);
update(,n,,i,);
mp[a[i]]=i;
}
}
while(q[j].r==i- && j<=m){
q[j].ans=query(,n,,q[j].l,q[j].r);
j++;
}
}
sort(q+,q+m+,cmp2);
for(i=;i<=m;i++) printf("%d\n",q[i].ans);
}
return ;
}
[swustoj 1021] Submissions of online judge的更多相关文章
- POJ 1861 Network (模版kruskal算法)
Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: Accepted: Special Judge Descripti ...
- POJ2175:Evacuation Plan(消负圈)
Evacuation Plan Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 5665Accepted: 1481Special J ...
- POJ 1734:Sightseeing trip
Sightseeing trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Special Judge ...
- HDU6023 Automatic Judge 2017-05-07 18:30 73人阅读 评论(0) 收藏
Automatic Judge Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others ...
- PAT 1075 PAT Judge[比较]
1075 PAT Judge (25 分) The ranklist of PAT is generated from the status list, which shows the scores ...
- 同余定理简单应用 - poj2769 - hdu 1021 - hdu 2035
同余问题 基本定理: 若a,b,c,d是整数,m是正整数, a = b(mod m), c = d(mod m) a+c = b+c(mod m) ac = bc(mod m) ax+cy = bx+ ...
- Automatic Judge
Description Welcome to HDU to take part in the second CCPC girls’ competition! A new automatic judge ...
- Virtual Judge使用指南
https://cn.vjudge.net/ Virtual Judge并不是常规的Online Judge平台,他通过爬取其他OJ的题目,让我们可以直接在VJ上查找并提交各种OJ的题目,然后将我们的 ...
- PTA 10-排序5 PAT Judge (25分)
题目地址 https://pta.patest.cn/pta/test/16/exam/4/question/677 5-15 PAT Judge (25分) The ranklist of PA ...
随机推荐
- 解决Strict Standards: Only variables should be passed by reference
这个错误发生在大家php调试程序用到一段代码里,那就是格式化显示出变量的函数functionrdump($arr)的第5行, 这段代码出自ecmall团队之手,但是ecmall已经很古董了,在php5 ...
- jsp多条件查询及查询结果在同一页面显示(原创)
第一步,建立main.jsp页面,使用frameset分上下两个框架,上部是query.jsp.下部是detail .detail显示的是showdetail.jsp的页面 <title> ...
- jsp+oracle 排序分页+Pageutil类
1.rownum和排序 Oracle中的rownum的是在取数据的时候产生的序号,所以想对指定排序的数据去指定的rowmun行数据就必须注意了. SQL> select rownum ,id,n ...
- Js setInterval与setTimeout(定时执行与循环执行)的代码(可以传入参数)
最近在做项目时用到了定时执行的js方法,setInterval与setTimeout时间长了不用有些生疏了,所以自己总结了一下,记下来,以便以后使用. Document自带的方法: 循环执行:var ...
- Python系统调用——运行其他程序
转载:http://blog.csdn.net/ssihc0/article/details/7738527 在Python中可以方便地使用os模块运行其他的脚本或者程序,这样就可以在脚本中直接使用其 ...
- java 取小数点后两位 不四舍五入,怎么做
java 取小数点后两位 不四舍五入,怎么做 正常版: //正常版: import java.text.DecimalFormat; import java.math.RoundingMode; De ...
- 如何在JavaScript里防止事件函数的高频触发和调用
网页中JavaScript最基本的功能是监听或响应用户的动作,这非常的有用.用户的动作有些频率非常高,有的十分罕见.有些监听器函数的执行如闪电般完成,而有些繁重的会把浏览器拖死.拿浏览器窗口的resi ...
- jquery.dragsort实现列表拖曳、排序
在一次工作中需要将功能模块实现拖曳并且排序,并且将排序结果保存到数据库,用户下次登录后直接读取数据库排序信息进行显示.LZ找了好多插件,最后发现 jquery.dragsort 这款插件是最好使用的, ...
- Java在mysql插入数据的时候的乱码问题解决
今天在使用hibernate的时候,插入mysql的数据中的中文总是显示乱码,之前出现过类似的问题,但是没有太在意,今天又发生了.所以向彻底的解决一下. 参考的博文: http://www.cnblo ...
- The 11th Zhejiang Provincial Collegiate Programming Contest->Problem G:G - Ternary Calculation
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3782 题意:把输入的三元运算用计算机运算出来. ; ci ...