Submissions of online judge(1021)

问题描述

An online judge is a system to test programs in programming contests. The system can compile and execute codes, and test them with pre-constructed data. Submitted code may be run with restrictions, including time limit, memory limit, security restriction and so on. The output of the code will be captured by the system, and compared with the standard output. The system will then return the result. 
Always, Online Judge systems also have a status page where a list of these results is shown. For example, http://acm.swust.edu.cn/ is an Online Judge of SWUST. A following list can be found in the system. As it shows, every submission has a Run ID and User ID. The Run ID is an incrementing sequence from 1 to N, with which a User ID is associated.
Mr. Yang wants to know, from Run ID L to R, how many different Users there are?

输入

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.

样例输入

2
3
1 1 4
2
1 2
2 3
5
1 1 2 1 3
3
1 5
2 4
3 5

样例输出

1
2
3
2
3
 
貌似改编自HDU、好题、离线处理
也可以不使用map,用离散化+vis标记
#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的更多相关文章

  1. POJ 1861 Network (模版kruskal算法)

    Network Time Limit: 1000MS Memory Limit: 30000K Total Submissions: Accepted: Special Judge Descripti ...

  2. POJ2175:Evacuation Plan(消负圈)

    Evacuation Plan Time Limit: 1000MSMemory Limit: 65536KTotal Submissions: 5665Accepted: 1481Special J ...

  3. POJ 1734:Sightseeing trip

    Sightseeing trip Time Limit: 1000MS Memory Limit: 65536K Total Submissions: Accepted: Special Judge ...

  4. 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 ...

  5. PAT 1075 PAT Judge[比较]

    1075 PAT Judge (25 分) The ranklist of PAT is generated from the status list, which shows the scores ...

  6. 同余定理简单应用 - 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+ ...

  7. Automatic Judge

    Description Welcome to HDU to take part in the second CCPC girls’ competition! A new automatic judge ...

  8. Virtual Judge使用指南

    https://cn.vjudge.net/ Virtual Judge并不是常规的Online Judge平台,他通过爬取其他OJ的题目,让我们可以直接在VJ上查找并提交各种OJ的题目,然后将我们的 ...

  9. 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 ...

随机推荐

  1. oracle通过透明网关连接mysql的配置

    之前配置过连接TD的,这一篇是介绍连接Mysql的配置很详细. http://blog.itpub.net/12679300/viewspace-1177222/

  2. Python垃圾回收机制详解

    一.垃圾回收机制 Python中的垃圾回收是以引用计数为主,分代收集为辅.引用计数的缺陷是循环引用的问题. 在Python中,如果一个对象的引用数为0,Python虚拟机就会回收这个对象的内存. #e ...

  3. wpf鼠标捕获与控件交互——UIElement.CaptureMouse

    应用场景是这样的,我需要拖动一个元素在屏幕上移动,注册了被移动元素的MouseMove事件,但是当鼠标移到被移动元素的外面时,移动失效,且鼠标的手势变成了普通的箭头形状,于是就找到了以下的解决方案. ...

  4. zxing-master core编译

    1.下载 Maven: http://maven.apache.org/download.cgi 2.下载完以后,设一下系统变量:MAVE_HOME 3.Path中加入%MAVEN_HOME%\bin ...

  5. 关于分区技术的索引 index

    关于分区技术---索引 Index 一.   分区索引分类: 本地前缀分区索引(local prefixedpartitioned index) 全局分区索引(global partitionedin ...

  6. Linux操作系统工作的基础

    简介: 本文根据 Linux™ 系统工作基础的分析,对存储程序计算机.堆栈(函数调用堆栈)机制和中断机制进行概述.文中将为您提供操作系统(内核)如何工作的细节,进一步从宏观概述结合关键点进行微观(CS ...

  7. obj转换成数组

    原则上obj是不能转换成数组的.首先array也是obj.只是一个特殊的object. obj一个很关键的点,是拥有成员和方法,撇开方法不说,obj就是一个key-value结构.也就是哈希数组,而j ...

  8. (转)基于即时通信和LBS技术的位置感知服务(一):提出问题及解决方案

    一.前言.提出问题 公司最近举行2011年度创新设计大赛,快年底了正打算写写2010年以来Android开发的心得与经验,正好同事出了个点子:假如A和B两个人分别在不同的地点,能不能实现这样的功能,让 ...

  9. unity3d与eclipse协同工作环境

    原地址:http://bbs.9ria.com/thread-212576-1-1.html 这个过程非常复杂.步骤一定要谨记 1,建立一个unity3d工程,然后自己丢点模型进去吧.然后设置导出时候 ...

  10. 深入理解c++中char*与wchar_t*与string以及wstring之间的相互转换

    本篇文章是对c++中的char*与wchar_t*与string以及wstring之间的相互转换进行了详细的分析介绍,需要的朋友参考下-复制代码 代码如下:    #ifndef USE_H_     ...