当前位置:网站首页>2022-7-9 personal qualifying 6 competition experience
2022-7-9 personal qualifying 6 competition experience
2022-07-26 08:18:00 【Fanshui 682】
The water problem is done quickly ..

A: Complex greed , All solutions are dp
C: Water problem
E: simulation
H: greedy , Scan line
I: greedy
K,L: Water problem
M: Thinking questions
N: Knapsack mixed template question
J:Poklon
Given an inclusion N An array of natural Numbers .
Then you need to answer Q Time to ask , Output interval every time [L,R] The number of natural numbers that occur exactly twice in .
Input
first line , Two integers N,Q, Represents the number of array elements and the number of queries .
The second line ,N It's an integer , Represents an element in an array .
Next Q That's ok , Two integers per line L,R, The interval of inquiry .
New knowledge : discretization ( No, old knowledge is also new bushi), offline , Mo team .
Discrete templates
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=a[i];
}
sort(b+1,b+1+n);
int len=unique(b+1,b+n+1)-(b+1);
rep(i,1,n){
a[i]=lower_bound(b+1,b+len+1,a[i])-b;
}Mo team template
struct shu{
int l,r,id;
}q[500010];
int n,m,block,ans;
int a[N],sum[N],fans[N];
bool cmp(shu a,shu b){
if ((a.r/block)==(b.r/block)){
return a.l<b.l;
}
return a.r<b.r;
}
void add(int x)
void del(int x)
void work(){
cin>>n>>m;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=m;i++){
cin>>q[i].l>>q[i].r;
q[i].id=i;
}
//block=n/(sqrt(m*2/3));
block=sqrt(n);
sort(q+1,q+m+1,cmp);
int l=0,r=0;
for(int i=1;i<=m;i++){
int ql=q[i].l,qr=q[i].r;
while(l<ql) del(l++);
while(r>qr) del(r--);
while(l>ql) add(--l);
while(r<qr) add(++r);
fans[q[i].id]=ans;
}
for(int i=1;i<=m;i++) cout<<fans[i]<<endl;
}Answer key ( The time complexity of being stuck )
#include <bits/stdc++.h>
#define int long long
#define CIO std::ios::sync_with_stdio(false)
#define rep(i, l, r) for (int i = l; i <= r; i++)
#define nep(i, r, l) for (int i = r; i >= l; i--)
#define pii pair<int,int>
using namespace std;
const int N=5e5+5;
struct shu{
int l,r,id;
}q[500010];
int n,m,block,ans;
int a[N],sum[N],fans[N];
bool cmp(shu a,shu b){
if ((a.r/block)==(b.r/block)){
return a.l<b.l;
}
return a.r<b.r;
}
void add(int x){
if (sum[a[x]]==1) ans++;
if (sum[a[x]]==2) ans--;
sum[a[x]]++;
}
void del(int x){
if (sum[a[x]]==3) ans++;
if (sum[a[x]]==2) ans--;
sum[a[x]]--;
}
int b[N];
void work(){
cin>>n>>m;
for(int i=1;i<=n;i++){
cin>>a[i];
b[i]=a[i];
}
sort(b+1,b+1+n);
int len=unique(b+1,b+n+1)-(b+1);
rep(i,1,n){
a[i]=lower_bound(b+1,b+len+1,a[i])-b;
}
for(int i=1;i<=m;i++){
cin>>q[i].l>>q[i].r;
q[i].id=i;
}
//block=n/(sqrt(m*2/3));
block=sqrt(n);
sort(q+1,q+m+1,cmp);
int l=0,r=0;
for(int i=1;i<=m;i++){
int ql=q[i].l,qr=q[i].r;
while(l<ql) del(l++);
while(r>qr) del(r--);
while(l>ql) add(--l);
while(r<qr) add(++r);
fans[q[i].id]=ans;
}
for(int i=1;i<=m;i++) cout<<fans[i]<<endl;
}
signed main(){
CIO;
work();
return 0;
}边栏推荐
- Zroi easy sum (generating function, block, DP, combination, polynomial)
- Shell homework the next day
- R language foundation
- mysql函数汇总之日期和时间函数
- File parsing (JSON parsing)
- Team members participate in 2022 China multimedia conference
- Day 4 homework
- Burp suite Chapter 6 how to use burp spider
- 2022/7/12 exam summary
- 2022 7/5 exam summary
猜你喜欢

Burp Suite - Chapter 1 burp suite installation and environment configuration

Guitar staff link Jasmine

咱就是来聊聊并发编程的三大核心问题。

Take out brother is the biggest support in this society

Burp Suite-第五章 如何使用Burp Target

Spotty music data client_ ID account

Burp Suite-第三章 如何使用Burp Suite代理

Introduction to arrays -- array

Strtus2历史漏洞复现

CentOS install mysql5.7
随机推荐
Condition judgment function of MySQL function summary
JSP implicit object -- scope
Day 3 homework
Burp Suite-第四章 SSL和Proxy高级选项
JSP action -- usebean action
The difference between abstract classes and interfaces
Burp Suite-第八章 如何使用Burp Intruder
File parsing (JSON parsing)
2W word detailed data Lake: concept, characteristics, architecture and cases
Flex three column layout
Common methods of string: construction method, other methods
Vscode utility shortcut
我,35岁了。
Burp suite Chapter 4 advanced options for SSL and proxy
[endnote] compilation of document types and abbreviations of document types
Exam summary on July 13, 2022
OSPF summary
Share high voltage ultra low noise LDO test results
苹果强硬新规:用第三方支付也要抽成,开发者亏大了!
CentOS install mysql5.7