TLE 求调
查看原帖
TLE 求调
1121995
2021zjhs005楼主2024/4/14 14:23

rt,莫队初学者,TLE 60 pts60\ \texttt{pts}。

或许是个愚蠢的错误,大佬勿喷。

#include <bits/stdc++.h>
using namespace std;

#define int long long
#define rep(i,x,y) for(register int i=x;i<=y;i++)
#define sc scanf
#define pr printf
#define inf 1e9
#define endline pr("\n")

inline int read() {
	int s = 0, w = 1;
	char c = getchar();
	while (!isdigit(c)) {
		if (c == '-') w = -1;
		c = getchar();
	}
	while (isdigit(c)) {
		s = (s << 1) + (s << 3) + (c ^ 48);
		c = getchar();
	}
	return s * w;
}

const int N=1e5+10;
int n,m,len,ans,curL,curR,cnt[N],a[N],belong[N];
bool answer[N];

struct node{
  int l , r , id;
  inline bool operator <(const node &b)const{
    return belong[l] == belong[r] ? r < b.r : l < b.l;
  }
};

node b[N];

inline void add(int pos){
  if((++cnt[a[pos]]) == 1) ans ++;
}

inline void del(int pos){
  if((--cnt[a[pos]]) == 0) ans --;
}

signed main() {
  n = read();
  m = read();
  rep(i,1,n) a[i] = read();
  len = sqrt(n);

  rep(i,1,m){
    b[i].l = read();
    b[i].r = read();
    b[i].id = i;
    belong[i] = i / len;
  }
  sort(b+1,b+1+m);

  rep(i,1,m){
    int L = b[i].l , R = b[i].r;
    while(curL < L) del(curL++);
    while(curL > L) add(--curL);
    while(curR < R) add(++curR);
    while(curR > R) del(curR--);
    if(ans == R - L + 1) answer[b[i].id] = 1;
  }

  rep(i,1,m)
    if(answer[i] == 1) pr("Yes\n");
    else pr("No\n");
  return 0;
}
2024/4/14 14:23
加载中...