无码av一区二区三区无码,在线观看老湿视频福利,日韩经典三级片,成 人色 网 站 欧美大片在线观看

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

??透傎愵}目講解_Different Integers

2022-04-22 10:20 作者:Clayton_Zhou  | 我要投稿

//?

//? https://ac.nowcoder.com/acm/contest/20322/J

#include <algorithm>

#include <iostream>

#include <cstring>

?using namespace std;

const int N = 1E5 + 100;

int n, m, block;

int arr[N]={ 0,1, 2, 3,4, 1,2,3 };


/*? 莫隊(duì)算法 (Mo's Algorithm)

*/

int res[N];

?int cnt[N];

struct Mo {

? ? int L, r, idx, lb;??

? ? ?bool operator < (const Mo &rhs) const {

? ? ? ? if (lb == rhs.lb) {

? ? ? ? ? ? return r < rhs.r;

? ? ? ? }

? ? ? ? return lb < rhs.lb;

? ? }

};

Mo qry[N];


int Q[N][2]={

1, 3,

3, 6,

2 ,3,

2 ,4,

1 ,3,

1 ,7,

3,5

};



?int sum=0;

void Insert(int x)

{

? ? cnt[x]++;//個(gè)數(shù)記錄

? ? if(cnt[x]==1) sum++;//如果滿足條件,就更新答案

}

void Remove(int x)

{

? ? cnt[x]--;

? ? if(cnt[x]==0) sum--;

}

int main() {

? ? ? n=7;m=7;

memset(cnt,0,sizeof cnt);

? ? /*

cin >> n>> m;


? ? for (int i = 1; i <= n; i++) {

? ? ? ? cin >> arr[i];

? ? }

? ? ?

? ? for (int i = 1; i <= m; i++) {

? ? ? ? cin >> qry[i].L?>> qry[i].r;

? ? ? ? qry[i].idx?= i;

? ? }*/


block = sqrt(n); ?

cout<<block<<endl;

for (int i = 1; i <= m; i++) {

? ? ? ? ?qry[i].L =Q[i-1][0]; qry[i].r=Q[i-1][1];

? ? ? ? qry[i].idx = i;

qry[i].lb= qry[i].L/block;

}

? ?

? ?sort(qry + 1, qry + 1 + m);

for (int i = 1; i <= m; i++) cout<<qry[i].idx<<"? ?";

cout<<endl;


? ? int left=0,r=n+1;

? ? for (int i = 1; i <= m; i++) {? ? ? ??

while(left<qry[i].L) Insert(arr[++left]);

cout <<" sum="<<sum<<" i="<<i<<" left="<<left<<" r="<<r<<endl;? ? ? ? ?

while(left>qry[i].L) Remove(arr[left--]);

? ? ? ? ? ?cout <<" sum="<<sum<<" i="<<i<<" left="<<left<<" r="<<r<<endl;

? ? ? ? ? ? while(r<qry[i].r) Remove(arr[r++]);

? ? ? ? ? ?cout <<" sum="<<sum<<" i="<<i<<" left="<<left<<" r="<<r<<endl;

? ? ? ? ? ? while(r>qry[i].r) Insert(arr[--r]);

cout <<" sum="<<sum<<" i="<<i<<" left="<<left<<" r="<<r<<endl<<endl;

? ? ? ? ? ? res[qry[i].idx]=sum;//記錄答案

? ? }

? ? for (int i = 1; i <= m; i++) {

? ? ? ? cout << res[i] << endl;

? ? }

? ? return 0;

}


??透傎愵}目講解_Different Integers的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國家法律
讷河市| 翁源县| 惠东县| 通州区| 上栗县| 丁青县| 格尔木市| 鄂托克旗| 临邑县| 南投市| 盖州市| 兴国县| 玉林市| 广西| 多伦县| 封丘县| 边坝县| 天台县| 卢氏县| 会东县| 阳西县| 张掖市| 深州市| 绥滨县| 漳平市| 彭泽县| 安丘市| 万源市| 临沧市| 江安县| 江油市| 桂东县| 阳谷县| 大埔县| 远安县| 宜丰县| 青浦区| 永济市| 大同县| 太保市| 双流县|