[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 ...
随机推荐
- http://phantomjs.org/page-automation.html
http://phantomjs.org/page-automation.html install brew curl -LsSf http://github.com/mxcl/homebrew/ta ...
- 在fedora 桌面上添加应用程序
在网上下了个android studio,这个程序只是的压缩包,解压后程序也只能在SHELL下敲入studio.sh才能运行 能不能向其他程序一样,在fedora桌面上找到应用程序,点击执行呢.在网上 ...
- ThinkPHP I方法
ThinkPHP的I方法是3.1.3版本新增的,如果你是之前的3.*版本的话,可以直接参考使用3.1快速入门教程系列的变量部分. 概述 正如你所见到的一样,I方法是ThinkPHP众多单字母函数中的新 ...
- ORACLE中常见的几种锁
ORACLE中常见的几种锁: 0:none 1:null 空 2:Row-S 行共享(RS):共享表锁,sub share 3:Row-X 行独占(RX):用于行的修改,sub exclusive 4 ...
- C#基础及记忆概念
在C#中,你给一个方法传输值类型参数时,实际上是使用的这个参数的一个副本,就是将原来的变量复制一份,然后传给一个方法,让其进行操作.所以在方法内部对参数的修改等不会对原来的参数造成影响(这个其实就是值 ...
- html template
https://wrapbootstrap.com/tag/single-page http://themeforest.net/ https://wrapbootstrap.com/themes h ...
- Raft、Zab
Raft.Zab 引言 <分布式系统理论进阶 - Paxos>介绍了一致性协议Paxos,今天我们来学习另外两个常见的一致性协议--Raft和Zab.通过与Paxos对比,了解Raft和Z ...
- LocalStorage 本地存储
首先自然是检测浏览器是否支持本地存储.在HTML5中,本地存储是一个window的属性,包括localStorage和sessionStorage,从名字应该可以很清楚的辨认二者的区别,前者是一直存在 ...
- C#跳出循环的几种方法的区别
break是循环结束执行,执行循环体后面的代码. continue是跳过本次循环未执行的代码,继续执行下一次循环. goto是跳到指定的指令去,你指哪,他跳到哪. return是函数返回,如果循环在M ...
- 关于ref与out的区别
写在最前面 这几天一直在公司接受培训,都是一些基础的知识,同时也乘着这个机会巩固一下自己的基础,基础太重要了.前些时一直看的是多线程方面的知识,接下来我会写一些其他方面的知识,毕竟作为一个实习新人得和 ...