criyle/codenet-compile-errors huggingface dataset:
Language: C++

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

//***---***---***---***---***---***---BEGIN USELESS CODE---***---***---***---***---***---***//

#define ll long long
#define ld long double
const char newl = '\n';

template<class T> void read(vector<T>& vt);
template<class T>
void read(T& args) { cin >> args; }
template<class A, class... B >
void read(A& argc, B&... argv) {
	read(argc);
	read(argv...);
}
template<class T>
void read(vector<T>& vt) {
	for(auto &a : vt)
		read(a);
}

string to_string(bool bo) { return (bo ? "true" : "false"); }
string to_string(char c) { return string(1, c); }
string to_string(const char* str) { return string(str);}
string to_string(string str) { return str; }
template<class T>
string to_string(T vt) {
	bool ft = 1;
	string res;
	for(auto &a : vt) {
		if(!ft)
			res += ' ';
		ft = 0;
		res += to_string(a);
	}
	return res;
}
string to_string(vector<bool> vt) {
	string res;
	bool ft = 1;
	for(int i = 0; i < (int)vt.size(); ++i) {
		if(!ft)
			res += ' ';
		ft = 0;
		res += char('0' + vt[i]);
	}
	return res;
}

template<class T>
void write(T args) { cout << to_string(args); }
template<class A, class... B>
void write(const A argc, const B... argv) {
	write(argc);
	write(argv...);
}

void print() { write(newl); }
template<class A, class... B>
void print(const A argc, const B... argv) {
	write(argc);
	if(sizeof...(argv))
		write(' ');
	print(argv...);
}

void DEBUGLOCAL() { cerr << ")" << newl; }
template<class A, class... B> 
void DEBUGLOCAL(A argc, B... argv) {
	cerr << to_string(argc);
	if(sizeof...(argv))
		cerr << ", ";
	DEBUGLOCAL(argv...);
}
#ifdef _DEBUG
#define dbg(...) cerr << "LINE(" << __LINE__ << ") [" << __FUNCTION__ << "] -> (" << #__VA_ARGS__ << "): (",DEBUGLOCAL(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

//***---***---***---***---***---***---END USELESS CODE---***---***---***---***---***---***//

int ts;
int n,m;
vector<int> c;
vector<vector<pair<int,int>>> q;
vector<int> ans, cnt;
vector<int> BIT;

void upd

Compiler output:
a.cc:92:9: error: expected initializer at end of input
   92 | void upd
      |         ^
Language: C++

#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <cmath>
using namespace std;

struct Mo {
    vector<int> left, right, index; // the interval's left, right, index
    vector<bool> v;
    int window;
    int nl, nr, ptr;
    
    Mo(int n) : window((int)sqrt(n)), nl(0), nr(0), ptr(0), v(n, false) { }
    
    /* push */
    void push(int l, int r) { left.push_back(l), right.push_back(r); }
    
    /* sort intervals */
    void build() {
        index.resize(left.size());
        iota(index.begin(), index.end(), 0);
        sort(begin(index), end(index), [&](int a, int b)
        {
            if (left[a] / window != left[b] / window) return left[a] < left[b];
            return bool((right[a] < right[b]) ^ (left[a] / window % 2));
        });
        
        //        sort(index.begin(), index.end(), [&](int a, int b) {
        //            if (left[a] / window != right[b] / window) return left[a] < left[b];
        //            else return right[a] < right[b];
        //        });
    }
    
    /* extend-shorten */
    void extend_shorten(int id) {
        v[id].flip();
        if (v[id]) insert(id);
        else erase(id);
    }
    
    /* next id of interval */
    int next() {
        if (ptr == index.size()) return -1;
        int id = index[ptr];
        while (nl > left[id]) extend_shorten(--nl);
        while (nr < right[id]) extend_shorten(nr++);
        while (nl < left[id]) extend_shorten(nl++);
        while (nr > right[id]) extend_shorten(--nr);
        return index[ptr++];
    }
    
    /* insert, erase (to be set appropriately) */
    void insert(int id);
    void erase(int id);
};

int N, Q;
int A[300001];
int res[200001];
int cnt[1000001];
int num_kind = 0;

void Mo::insert(int id) {
    int val = A[id];
    if (cnt[val] == 0) ++num_kind;
    ++cnt[val];
}

void Mo::erase(int id) {
    int val = A[id];
    --cnt[val];
    if (cnt[val] == 0) --num_kind;
}

int main() {
    cin>>N>>Q;
    for(int i = 0; i < N; i++) cin>>a[i];
    Mo mo(N);
    for(int i = 0; i < Q; i++) {
        int l, r; scanf("%d %d", &l, &r);
        mo.push(--l, r);
    }
    mo.build();
    for(int i = 0; i < Q; i++) res[mo.next()] = num_kind;
    for(int i = 0; i < Q; i++) cout<<res[i]<<endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:78:37: error: 'a' was not declared in this scope
   78 |     for(int i = 0; i < N; i++) cin>>a[i];
      |                                     ^
Language: C++

from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate, combinations, product
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor
from operator import mul
from functools import reduce


sys.setrecursionlimit(2147483647)
INF = 10 ** 13
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().rstrip().split()
def S(): return sys.stdin.readline().rstrip()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 998244353


class BIT:
    def __init__(self, size):
        self.bit = [0] * size
        self.size = size
        self.total = 0

    def add(self, i, w):
        x = i + 1
        self.total += w
        while x <= self.size:
            self.bit[x - 1] += w
            x += x & -x
        return

    def sum(self, i):
        res = 0
        x = i + 1
        while x:
            res += self.bit[x - 1]
            x -= x & -x
        return res

n, q = LI()
ans = [0] * q
C = LI()
Q = []
for i in range(q):
    l, r = LI()
    Q += [[l-1, 0, i]]
    Q += [[r-1, 1, i]]

Q.sort()
Q += [(INF, 0, 0)]
D = defaultdict(lambda:-1)
DD = {}
bit = BIT(q + 1)
now = 0
q_now = 0
l_idx = [INF] * (q + 1)
for i in range(n):
    col = C[i]
    last_q_now = D[col]
    if last_q_now == -1:
        bit.add(0, 1)
    else:
        bit.add(last_q_now, 1)
# print(bisect_right(l_idx, last_idx), "a")
    while Q[now][0] <= i:
        idx, flg, qq = Q[now]
        if flg:
            ans[qq] = bit.sum(DD[qq])
        else:
            DD[qq] = q_now
            l_idx[q_now] = idx
            q_now += 1
        now += 1
    D[col] = q_now
    bit.add(q_now, -1)
#    print(q_now, "b")


for i in ans:
    print(i)


Compiler output:
a.cc:76:3: error: invalid preprocessing directive #print
   76 | # print(bisect_right(l_idx, last_idx), "a")
      |   ^~~~~
a.cc:88:6: error: invalid preprocessing directive #print
   88 | #    print(q_now, "b")
      |      ^~~~~
a.cc:1:1: error: 'from' does not name a type
    1 | from collections import defaultdict, deque, Counter
      | ^~~~
a.cc:65:1: error: 'bit' does not name a type
   65 | bit = BIT(q + 1)
      | ^~~
Language: C++

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
using namespace std;
int read(){
    char x;
    while((x = getchar()) > '9' || x < '0') ;
    int u = x - '0';
    while((x = getchar()) <= '9' && x >= '0') u = (u << 3) + (u << 1) + x - '0';
    return u;
}
int buf[105];  
inline void write(int i){  
    int p = 0;  
    if(i == 0) p++;  
    else while(i) {  
        buf[p++] = i % 10;  
        i /= 10;  
    }  
    for(int j = p-1; j >= 0; j--) putchar('0' + buf[j]);  
} 

const int maxn = 5e5+5;
int a[maxn],ans[maxn],cnt[maxn],res=0,n,m,bl;
struct node{
	int l,r,id;
	int block;
}q[maxn]; 

bool cmp(const node a,const node b){
	return a.block^b.block?a.l<b.l:((a.block&1)?a.r<b.r:a.r>b.r);
}

inline void del(int x){
	--cnt[a[x]];
	if(!cnt[a[x]])--res;
}
inline void add(int x){
	if(!cnt[a[x]])++res;
	++cnt[a[x]];
}

int main() {
	int n,m;
	n=read();m=read();
	bl=n/sqrt(2/3*m);
	for(int i=1;i<=n;++i)a[i]=read();
	
	for(int i=1;i<=m;++i){
		q[i].l=read(),q[i].r=read();
		q[i].id=i;
		q[i].block=e[i].l/bl;
	}
	sort(q+1,q+1+m,cmp);
	
	int l=q[1].l,r=q[1].l-1;
	for(int i=1;i<=m;++i){
		int stdl=q[i].l,stdr=q[i].r;
		
		while(l<stdl)del(l++);
		
		while(l>stdl)add(--l);
		
		while(r<stdr)add(++r);
		
		while(r>stdr)del(r--);
		
		ans[q[i].id]=res;
	}
	
	for(int i=1;i<=m;++i)write(ans[i]),printf("\n");
	return 0;
}

Compiler output:
a.cc: In function 'int main()':
a.cc:64:28: error: 'e' was not declared in this scope
   64 |                 q[i].block=e[i].l/bl;
      |                            ^
Language: C++

#include <bits/stdc++.h>
using namespace std;
#define fr first
#define sc second
#define Fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int block;
int m[2000000];
int a[2000000];
struct query{
  int l,r,idx;  
};
int value = 0;
bool comper(query a, query b)
{
    if(a.l / Block != b.l / Block)
        return a.l < b.l;
    return a.l / Block % 2 ? a.r < b.r : a.r > b.r;
}

void add(int pos)
{
    int val=a[pos];
    m[val]++;
    if (m[val]==1)
    {
        value++;
    }
    else if (!m[val])
    {
        value--;
    }
}
void remove(int pos)
{
    int val=a[pos];
    m[val]--;
    if (!m[val])
    {
        value--;
    }
}

int main(void){
    Fast;
int n, q;
cin >> n >> q;
block = sqrt(n);


for(int i = 1; i < n + 1; i++)
cin >> a[i];

query qr [q];

for(int i = 0; i < q; i++)
cin >> qr[i].l >> qr[i].r,
qr[i].idx = i;


sort(qr, qr + q, comper);

set<int>s;
int L = 1, R = 1,ml = 0, mr = 0;
int ans[q];

for(int i = 0; i < q; i++){
   int L = qr[i].l;
   int R = qr[i].r;
   while(mr < R)
       mr++, add(mr);
       
       
    while(ml >  L)
       ml--, add(ml);

    
    while(ml < L)
      remove(ml), ml++;
    
    while(mr > R)
      remove(mr), mr--;
     
     
        ans[qr[i].idx] = value;
    
}


for(int i = 0; i < q; i++)
cout << ans[i] << "\n";








}

Compiler output:
a.cc: In function 'bool comper(query, query)':
a.cc:15:14: error: 'Block' was not declared in this scope; did you mean 'block'?
   15 |     if(a.l / Block != b.l / Block)
      |              ^~~~~
      |              block
a.cc:17:18: error: 'Block' was not declared in this scope; did you mean 'block'?
   17 |     return a.l / Block % 2 ? a.r < b.r : a.r > b.r;
      |                  ^~~~~
      |                  block
Language: C++

#line 1 "main.cpp"
#include <bits/stdc++.h>
using namespace std;
using VI = vector<int>;
#define rep(i, n) for (int i = 0; i < (n); i++)

int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);

  int n, q; cin >> n >> q;
  VI c(n); rep(i, n) cin >> c[i];
  vector<pair<int, int>> lr(q); rep(i, q) cin >> lr[i].first >> lr[i].second;
  rep(i, q) lr[i].first--;

  const int sq = 700;
  vector<tuple<int, int, int>> lri(q);
  rep(i, q) lri[i] = make_tuple(lr[i].first / sq, lr[i].second, i);
  sort(all(lri));

  VI ans(q);

  VI cnt(n+1);
  int prev = -1;
  int lx, rx;
  int sum = 0;
  VI pushed;
  for (auto [ls, r, i] : lri) {
    if (ls != prev) {
      for (auto cx : pushed) cnt[cx] = 0;
      pushed.clear();
      lx = rx = r;
      prev = ls;
    }
    int l = lr[i].first;
    int cx;
    while (lx > l) if (cnt[cx=c[--lx]]++ == 0) sum += 1, pushed.push_back(cx);
    while (lx < l) if (--cnt[cx=c[lx++]] == 0) sum -= 1;
    while (rx < r) if (cnt[cx=c[rx++]]++ == 0) sum += 1, pushed.push_back(cx);
    assert(rx == r);
    ans[i] = sum;
  }
  rep(i, q) cout << ans[i] << "\n";
}


Compiler output:
main.cpp: In function 'int main()':
main.cpp:17:8: error: 'all' was not declared in this scope; did you mean 'std::filesystem::perms::all'?
In file included from /usr/include/c++/14/filesystem:51,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:200,
                 from main.cpp:1:
/usr/include/c++/14/bits/fs_fwd.h:158:7: note: 'std::filesystem::perms::all' declared here
  158 |       all               =  0777,
      |       ^~~
Language: C++

//header{{{
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <boost/hana/functional/fix.hpp>
#include <boost/sort/spreadsort/spreadsort.hpp>
//#include <boost/graph/adjacency_list.hpp>
//#include <boost/graph/dijkstra_shortest_paths.hpp>
//#include <boost/graph/graph_utility.hpp>
//#include <boost/multiprecision/cpp_int.hpp>
  
using namespace std;
//using namespace boost::multiprecision;
//using namespace boost::math;

/*
typedef boost::adjacency_list<boost::listS, boost::vecS, boost::undirectedS,
        boost::no_property, boost::property<boost::edge_weight_t, int> > Graph;
*/


#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define all(x) (x).begin(),(x).end()
#define Fixed fixed << setprecision(12)
#define FixPoint boost::hana::fix
#define bsort boost::sort::spreadsort::spreadsort
#define int int_fast64_t
using pii = pair<int,int>;
constexpr int INF  = 0x3f3f3f3f;
constexpr long long LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9+7; 
constexpr int mod2 = 998244353;

template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }

template <class T> using min_heap = priority_queue<T,vector<T>,greater<T> >;
template <class T> using max_heap = priority_queue<T>;
template <class A, class B> using umap = unordered_map<A,B>;
  
inline int square(int a){ return a * a;}
inline int updiv(int a,int b){ return (a + b - 1) / b; }

constexpr int dx[] = {1,0,-1,0,1,1,-1,-1};
constexpr int dy[] = {0,-1,0,1,1,-1,-1,1};
//}}}

template< typename T >
struct BinaryIndexedTree {
  vector< T > data;
 
  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }
 
  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }
 
  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

signed main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout.setf(ios_base::fixed);
    cout.precision(10);

  	int n, q;
    cin >> n >> q;
 
    vector<int> a(n + 1);
 
    reps(i,n){
        cin >> a[i];
    }
 
    vector<tuple<int, int, int> > querys;
 
    rep(i,q){
        int l, r;
        cin >> l >> r;
        querys.emplace_back(r, l, i);
    }
 
    bsort(all(querys));
 
    vector<int> v(n + 1), res(q);
    BinaryIndexedTree<int> bit(n + 5);
 
    int R = 1;
    for(auto &&[r, l, query_num] : querys){
        for(; R <= r; ++R){
            if(v[a[R]] != -1){
                bit.add(v[a[R]], -1);
            }
            v[a[R]] = R;
            bit.add(R, 1);
        }
        res[query_num] = bit.sum(r) - bit.sum(l-1);
    }
 
    for(auto &&e : res){
        cout << e << '\n';
    }

    return 0;
}


Compiler output:
a.cc:4:10: fatal error: boost/hana/functional/fix.hpp: No such file or directory
    4 | #include <boost/hana/functional/fix.hpp>
      |          ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
compilation terminated.
Language: Java

package abc174;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.IntStream;

/**
 * 解説通りに実装したソースコード
 * 
 * https://atcoder.jp/contests/abc174/submissions/15644133 と https://atcoder.jp/contests/abc174/submissions/15644479
 * にも参考<br/>
 * java.util.Scanner が遅いため、https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb のScannerを使用
 */
public class ProblemF {

	public static void main(String[] args) {
		try (InputStreamReader isr = new InputStreamReader(System.in); BufferedReader br = new BufferedReader(isr)) {
			String[] strings = br.readLine().split(" ");
			int n = Integer.parseInt(strings[0]), q = Integer.parseInt(strings[1]);
			int[] c = new int[n];
			String[] cs = br.readLine().split(" ", n);
			IntStream.range(0, n).forEach(i -> c[i] = Integer.parseInt(cs[i]));
			@SuppressWarnings("unchecked")
			List<Integer>[] queryIndexes = new List[n + 1], queryLefts = new List[n + 1];
			IntStream.range(0, q).forEach(i -> {
				try {
					String[] s = br.readLine().split(" ");
					int l = Integer.parseInt(s[0]), r = Integer.parseInt(s[1]);
					if (null == queryIndexes[r]) {
						queryIndexes[r] = new ArrayList<>();
					}
					queryIndexes[r].add(i);
					if (null == queryLefts[r]) {
						queryLefts[r] = new ArrayList<>();
					}
					queryLefts[r].add(l);
				} catch (IOException e) {
					e.printStackTrace();
				}
			});
			BinaryIndexedTree bit = new BinaryIndexedTree(n + 1);
			int[] answers = new int[q], indexes = new int[n + 1];
			Arrays.fill(indexes, 0);
			for (int i = 0; i < n; i++) {
				if (indexes[c[i]] > 0) {
					bit.add(indexes[c[i]], -1);
				}
				bit.add(i + 1, 1);
				indexes[c[i]] = i + 1;
				if (null != queryIndexes[i + 1]) {
					for (int j = 0; j < queryIndexes[i + 1].size(); j++) {
						answers[queryIndexes[i + 1].get(j)] = bit.sum(queryLefts[i + 1].get(j), i + 1);
					}
				}
			}
			Arrays.stream(answers).forEach(System.out::println);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

//	private static class Query implements Comparable<Query> {
//		int index;
//		int left;
//		int right;
//
//		Query(int index, int left, int right) {
//			super();
//			this.index = index;
//			this.left = left;
//			this.right = right;
//		}
//
//		@Override
//		public int compareTo(Query o) {
//			return this.right - o.right;
//		}
//	}

	private static class BinaryIndexedTree {
		int size;
		int[] data;

		BinaryIndexedTree(int size) {
			super();
			this.size = size;
			data = new int[size];
			Arrays.fill(data, 0);
		}

		void add(int index, int value) {
			for (int i = index; i < size; i += (i & -i)) {
				data[i] += value;
			}
		}

		int sum(int index) {
			int sum = 0;
			for (int i = index; i > 0; i -= (i & -i)) {
				sum += data[i];
			}
			return sum;
		}

		int sum(int from, int to) {
			return sum(to) - sum(from - 1);
		}
	}
}


Compiler output:
Main.java:18: error: class ProblemF is public, should be declared in a file named ProblemF.java
public class ProblemF {
       ^
1 error
Language: Java

mport java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

/**
 * 解説通りに実装したソースコード
 * 
 * https://atcoder.jp/contests/abc174/submissions/15644133 と https://atcoder.jp/contests/abc174/submissions/15644479
 * にも参考
 */
public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), q = scanner.nextInt();
			int[] c = new int[n];
			for (int i = 0; i < n; i++) {
				c[i] = scanner.nextInt();
			}
			// IntStream.range(0, n).forEach(i -> c[i] = scanner.nextInt());
			Queue<Query> queue = new PriorityQueue<>();
			for (int i = 0; i < q; i++) {
				// IntStream.range(0, q).forEach(i -> {
				int l = scanner.nextInt(), r = scanner.nextInt();
				queue.add(new Query(i, l, r));
			}
			// });
			BinaryIndexedTree bit = new BinaryIndexedTree(n + 1);
			int[] answers = new int[q], indexes = new int[n + 1];
			// Arrays.fill(indexes, 0);
			for (int i = 0; i < n; i++) {
				if (indexes[c[i]] > 0) {
					bit.add(indexes[c[i]], -1);
				}
				bit.add(i + 1, 1);
				indexes[c[i]] = i + 1;
				while (!queue.isEmpty() && (i + 1 == queue.peek().right)) {
					Query query = queue.poll();
					answers[query.index] = bit.sum(query.left, query.right);
				}
				if (queue.isEmpty()) {
					break;
				}
			}
			Arrays.stream(answers).forEach(System.out::println);
		}
	}

	private static class Query implements Comparable<Query> {
		int index;
		int left;
		int right;

		Query(int index, int left, int right) {
			super();
			this.index = index;
			this.left = left;
			this.right = right;
		}

		@Override
		public int compareTo(Query o) {
			return this.right - o.right;
		}
	}

	private static class BinaryIndexedTree {
		int size;
		int[] data;

		BinaryIndexedTree(int size) {
			super();
			this.size = size;
			data = new int[size];
			// Arrays.fill(data, 0);
		}

		void add(int index, int value) {
			for (int i = index; i < size; i += (i & -i)) {
				data[i] += value;
			}
		}

		int sum(int index) {
			int sum = 0;
			for (int i = index; i > 0; i -= (i & -i)) {
				sum += data[i];
			}
			return sum;
		}

		int sum(int from, int to) {
			return sum(to) - sum(from - 1);
		}
	}
}


Compiler output:
Main.java:1: error: class, interface, enum, or record expected
mport java.util.Arrays;
^
Main.java:2: error: class, interface, enum, or record expected
import java.util.PriorityQueue;
^
Main.java:3: error: class, interface, enum, or record expected
import java.util.Queue;
^
Main.java:4: error: class, interface, enum, or record expected
import java.util.Scanner;
^
4 errors
Language: Java

import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.Scanner;

/**
 * 解説通りに実装したソースコード
 * 
 * https://atcoder.jp/contests/abc174/submissions/15644133 と https://atcoder.jp/contests/abc174/submissions/15644479
 * にも参考
 */
public class ProblemF {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), q = scanner.nextInt();
			int[] c = new int[n];
			for (int i = 0; i < n; i++) {
				c[i] = scanner.nextInt();
			}
			// IntStream.range(0, n).forEach(i -> c[i] = scanner.nextInt());
			Queue<Query> queue = new PriorityQueue<>();
			for (int i = 0; i < q; i++) {
				// IntStream.range(0, q).forEach(i -> {
				int l = scanner.nextInt(), r = scanner.nextInt();
				queue.add(new Query(i, l, r));
			}
			// });
			BinaryIndexedTree bit = new BinaryIndexedTree(n + 1);
			int[] answers = new int[q], indexes = new int[n + 1];
			// Arrays.fill(indexes, 0);
			for (int i = 0; i < n; i++) {
				if (indexes[c[i]] > 0) {
					bit.add(indexes[c[i]], -1);
				}
				bit.add(i + 1, 1);
				indexes[c[i]] = i + 1;
				while (!queue.isEmpty() && (i + 1 == queue.peek().right)) {
					Query query = queue.poll();
					answers[query.index] = bit.sum(query.left, query.right);
				}
				if (queue.isEmpty()) {
					break;
				}
			}
			Arrays.stream(answers).forEach(System.out::println);
		}
	}

	private static class Query implements Comparable<Query> {
		int index;
		int left;
		int right;

		Query(int index, int left, int right) {
			super();
			this.index = index;
			this.left = left;
			this.right = right;
		}

		@Override
		public int compareTo(Query o) {
			return this.right - o.right;
		}
	}

	private static class BinaryIndexedTree {
		int size;
		int[] data;

		BinaryIndexedTree(int size) {
			super();
			this.size = size;
			data = new int[size];
			// Arrays.fill(data, 0);
		}

		void add(int index, int value) {
			for (int i = index; i < size; i += (i & -i)) {
				data[i] += value;
			}
		}

		int sum(int index) {
			int sum = 0;
			for (int i = index; i > 0; i -= (i & -i)) {
				sum += data[i];
			}
			return sum;
		}

		int sum(int from, int to) {
			return sum(to) - sum(from - 1);
		}
	}
}


Compiler output:
Main.java:12: error: class ProblemF is public, should be declared in a file named ProblemF.java
public class ProblemF {
       ^
1 error
Language: C++

#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;

//入力
ll n,q;
vector<ll>c;
vector<ll>l,r;

/* BIT: RAQ対応BIT
    初期値は a_1 = a_2 = ... = a_n = 0
    ・add(l,r,x): [l,r) に x を加算する
    ・sum(i): a_1 + a_2 + ... + a_i を計算する
    計算量は全て O(logn)
*/
template <typename T>
struct BIT {
    int n;             // 要素数
    vector<T> bit[2];  // データの格納先
    BIT(int n_) { init(n_); }
    void init(int n_) {
        n = n_ + 1;
        for (int p = 0; p < 2; p++) bit[p].assign(n, 0);
    }
    void add_sub(int p, int i, T x) {
        for (int idx = i; idx < n; idx += (idx & -idx)) {
            bit[p][idx] += x;
        }
    }
    void add(int l, int r, T x) {  // [l,r) に加算
        add_sub(0, l, -x * (l - 1));
        add_sub(0, r, x * (r - 1));
        add_sub(1, l, x);
        add_sub(1, r, -x);
    }
    T sum_sub(int p, int i) {
        T s(0);
        for (int idx = i; idx > 0; idx -= (idx & -idx)) {
            s += bit[p][idx];
        }
        return s;
    }
    T sum(int i) { return sum_sub(0, i) + sum_sub(1, i) * i; }
};

int main(){
    cin >> n >> q;
    c.resize(n+1);
    rep(i,n){
        cin>>c[i+1];
    }
    vector<ll>lastAppeared(n+1,-1);
    vector<P>query;
    rep(i,q){
        ll l,r;
        cin >> l >> r;
        query.push_back({r,l});
    }
    sort(query.begin(),query.end());
    BIT<int> bit(n);
    ll j = 0;
    rep(i,q){
        ll l = query[i].second;
        ll r = query[i].first;
        for(int k=j+1;k<=r;k++){
            ll now = c[k];

            if(lastAppeared[now]!=-1){
                bit.add(lastAppeared[now],lastAppeared[now]+1,-1);
            }
            lastAppeared[now]=k;
            bit.add(k,k+1,1);
            cout << bit.sum(r)-bit.sum(l-1) << endl;           
        }
        j = r;
        
    }
    /*
    rep(i,n){
        cout << bit.sum(i+1)-bit.sum(i) << "last: " << lastAppeared[i] << endl;
    }
    */
    return 0;
}


Compiler output:
a.cc:80:53: error: stray '\16' in program
   80 |             cout << bit.sum(r)-bit.sum(l-1) << endl;<U+000E>
      |                                                     ^~~~~~~~
Language: C++

// #include<bits/stdc++.h>
#include<iostream>
#include<cmath>

#define fi first
#define se second
#define pb push_back
 
#define limit (int) (5e5 + 5)

#define maxn (long long int) (2147483647);

using namespace std;
using lli = long long int;
using ulli = unsigned long long int;
using ld = long double;

int n,q,sn,ca=0;
int a[limit],cnt[limit] = {},ans[limit];

struct query
{
    int in;
    int l,r;

    bool operator > (query rhs) const
    {
        if ((l)/sn != (rhs.l)/sn)
        {
            return l > rhs.l;
        }

        if (r != rhs.r)
        {
            return r > rhs.r;
        }

        return l > rhs.l;
    }

    bool operator < (query rhs) const
    {
        if ((l)/sn != (rhs.l)/sn)
        {
            return l < rhs.l;
        }

        if (r != rhs.r)
        {
            return r < rhs.r;
        }

        return l < rhs.l;
        
    }

    
} ql[limit];

int sgn(int a)
{
    if (a >= 0)
    {
        return 1;
    }

    return -1;
}

int main()
{
    ios_base::sync_with_stdio(false);
    // cin.tie(NULL);

    cin >> n >> q;
    sn = sqrt(n);

    for (int i = 1; i <= n; ++i)
    {
        cin >> a[i];
        // a[i]--;
    }

    for (int i = 0; i < n; ++i)
    {
        cin >> ql[i].l >> ql[i].r;
        ql[i].in = i;
    }

    sort(ql,ql+q);

    int lp = ql[0].l,rp = ql[0].r;

    for (int i = ql[0].l; i <= ql[0].r; ++i)
    {
        cnt[a[i]]++;

        if (cnt[a[i]] == 1)
            ca++;
    }

    ans[ql[0].in] = ca;

    int d;

    for (int i = 1; i < q; ++i)
    {
        d = sgn(ql[i].l-lp);    

        while(lp != ql[i].l)
        {
            if (d > 0)
                cnt[a[lp]]--;
            else
                cnt[a[lp-1]]++;

            if (cnt[a[lp]] == 0 && d==1)
                ca--;

            if (d == -1) if (cnt[a[lp-1]] == 1) ca++;

            lp += d;
        }


        d = sgn(ql[i].r-rp);

        while(rp != ql[i].r)
        {
            if (d < 0)
                cnt[a[rp]]--;
            else
                cnt[a[rp+1]]++;

            if (cnt[a[rp]] == 0 && d==-1)
                ca--;

            if (d == 1) if(cnt[a[rp+1]] == 1) ca++;

            rp += d;
        }

        ans[ql[i].in] = ca;
    }

    for (int i = 0; i < q; ++i)
    {
        cout << ans[i] << "\n";
    }
    
    return 0;
}










Compiler output:
a.cc: In function 'int main()':
a.cc:90:5: error: 'sort' was not declared in this scope; did you mean 'sqrt'?
   90 |     sort(ql,ql+q);
      |     ^~~~
      |     sqrt
Language: C++

#include <cassert>
#include <cmath>
#include <functional>
#include <vector>
#include <numeric>

template <class Add, class Del>
class Mo
{
    Add add; Del del;
    std::vector<size_t> lft, rgt, ord;
    // std::vector<size_t>::iterator itr;
    int itr=0;
    bool made;
    size_t width, nl, nr;

    void make()
    {
        made = true;
        ord.resize(lft.size());
        std::iota(ord.begin(), ord.end(), 0);
        std::sort(ord.begin(), ord.end(),
        [&](size_t x, size_t y)
        {
            if(lft[x] / width != lft[y] / width) return lft[x] < lft[y];
            return rgt[x] < rgt[y];
        });
        //itr = ord.begin();
    }

public:
    Mo(size_t n = 0, Add add = Add(), Del del = Del())
        : add(add), del(del), made(), width(sqrt(n)), nl(), nr() {}

    void set(size_t l, size_t r)
    {
        assert(!made);
        lft.emplace_back(l), rgt.emplace_back(r);
    }

    size_t process()
    {
        const size_t id = ord[itr++], l = lft[id], r = rgt[id];
        while(nl > l) add(--nl);
        while(nr < r) add(nr++);
        while(nl < l) del(nl++);
        while(nr > r) del(--nr);
        return id;
    }
};

#include <cstdio>

main()
{
    int n,q;
    scanf("%d%d",&n,&q);
    int c[501010];
    int su[501010]={};
    int kind=0;
    auto add=[&](size_t i)
    {
        if(!su[c[i]]++) ++kind;
    };
    auto del=[&](size_t i)
    {
        if(!--su[c[i]]) --kind;
    };
    for(int i=0; i<n; i++) scanf("%d",c+i);
    Mo mo(n,add,del);
    for(int i=0,l,r; i<q; i++)
    {
        scanf("%d%d",&l,&r);
        mo.set(l-1,r);
    }
  	mo.make();
    int ans[501010];
    for(int i=0; i<q; i++)
    {
        int id=mo.process();
        ans[id]=kind;
    }
    for(int i=0; i<q; i++) printf("%d\n",ans[i]);
}


Compiler output:
a.cc: In member function 'void Mo<Add, Del>::make()':
a.cc:22:14: error: 'sort' is not a member of 'std'; did you mean 'sqrt'?
   22 |         std::sort(ord.begin(), ord.end(),
      |              ^~~~
      |              sqrt
a.cc: At global scope:
a.cc:54:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   54 | main()
      | ^~~~
a.cc: In function 'int main()':
a.cc:76:16: error: 'void Mo<Add, Del>::make() [with Add = main()::<lambda(size_t)>; Del = main()::<lambda(size_t)>]' is private within this context
   76 |         mo.make();
      |         ~~~~~~~^~
a.cc:17:10: note: declared private here
   17 |     void make()
      |          ^~~~
Language: C++

int N, A[300000], Q;
int ans[200000];
int cnt[1000001], sum;

void Mo::add(int idx)
{
  if(cnt[A[idx]]++ == 0) ++sum;
}

void Mo::del(int idx)
{
  if(--cnt[A[idx]] == 0) --sum;
}

int main()
{
  scanf("%d", &N);
  for(int i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
  scanf("%d", &Q);
  Mo mo(N);
  for(int i = 0; i < Q; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    mo.insert(--a, b);
  }
  mo.build();
  for(int i = 0; i < Q; i++) {
    ans[mo.process()] = sum;
  }
  for(int i = 0; i < Q; i++) {
    printf("%d\n", ans[i]);
  }
}

Compiler output:
a.cc:5:6: error: 'Mo' has not been declared
    5 | void Mo::add(int idx)
      |      ^~
a.cc:10:6: error: 'Mo' has not been declared
   10 | void Mo::del(int idx)
      |      ^~
a.cc: In function 'int main()':
a.cc:17:3: error: 'scanf' was not declared in this scope
   17 |   scanf("%d", &N);
      |   ^~~~~
a.cc:22:3: error: 'Mo' was not declared in this scope
   22 |   Mo mo(N);
      |   ^~
a.cc:26:5: error: 'mo' was not declared in this scope
   26 |     mo.insert(--a, b);
      |     ^~
a.cc:28:3: error: 'mo' was not declared in this scope
   28 |   mo.build();
      |   ^~
a.cc:33:5: error: 'printf' was not declared in this scope
   33 |     printf("%d\n", ans[i]);
      |     ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | int N, A[300000], Q;
Language: C++

#include<bits/stdc++.h>
#define REP(i,n) for (int i = 1; i <= n; i++)
#define mod 1000000007
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define lli long long int
#define INF 1000000000
#define mxn 5000001
#define endl '\n'
#define BLOCK 750
const double PI = 3.141592653589793238460;
typedef std::complex<double> Complex;
typedef std::valarray<Complex> CArray;
 
using namespace std;
struct query{
	int l;
	int r;
	int i;
};
struct query{
	int l;
	int r;
	int i;
};
query Q[mxn];
int ar[mxn] , ans[mxn];
int fre[mxn];
int cnt = 0;
bool comp(query a , query b)
{
	if(a.l / BLOCK != b.l/BLOCK)
	return a.l/BLOCK < b.l/BLOCK;
 
	return a.r < b.r;
}
 
void add(int pos)
{
	fre[ar[pos]]++;
	if(fre[ar[pos]] == 1)
	cnt++;
}
 
void remove(int pos)
{
	fre[ar[pos]]--;
	if(fre[ar[pos]] == 0)
	cnt--;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	
	int n , q;
	cin>>n;
	for(int i=0;i<n;i++)
	cin>>ar[i];
	
	cin>>q;
	for(int i=0;i<q;i++){
		cin>>Q[i].l>>Q[i].r;
		Q[i].i = i , Q[i].l-- , Q[i].r--;
	}
	
	sort(Q , Q+q , comp);
	
	//why ML = 0 , and MR = -1?
	int ML = 0 , MR = -1;
	for(int i=0;i<q;i++)
	{
		int L = Q[i].l;
		int R = Q[i].r;
		
		while(ML > L)
		ML-- , add(ML);
		
		while(MR < R)
		MR++ , add(MR);
		
		while(ML < L)
		remove(ML) , ML++;
		
		while(MR > R)
		remove(MR) , MR--;
		
		ans[Q[i].i] = cnt;
	}
	
	for(int i=0;i<q;i++)
	cout<<ans[i]<<'\n';
}

Compiler output:
a.cc:25:8: error: redefinition of 'struct query'
   25 | struct query{
      |        ^~~~~
a.cc:20:8: note: previous definition of 'struct query'
   20 | struct query{
      |        ^~~~~
Language: C++

#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
struct query
{
    ll l, r, id;
};
struct BIT
{
    const int N = 2e6;
    std::vector<ll> b(N);

    void update(ll id, ll val)
    {
        while(id < N)
        {
            b[id] += val;
            id += (id & (-id));
        }

    }
    ll query(ll id)
    {
        ll ans = 0;
        while(id)
        {
            ans += b[id];
            id -= (id & (-id));
        }
        return ans;
    }
};
bool cmp(query &a, query &b)
{
    return a.r <= b.r;
}
void solve()
{
    ll n, q, x, l, r;
    BIT bb;
    cin >> n >> q;
    std::vector<ll> v(n + 1), res(q + 1);
    map<ll, ll> last;
    for(int i = 1; i <= n; i++) cin >> v[i];
    std::vector<query> qq(q);

    for(int i = 0; i < q; i++)
    {
        cin >> qq[i].l >> qq[i].r;
    }
    sort(qq.begin(), qq.end(), cmp);
    for(int i = 1, j = 0; i <= n; i++)
    {
        if(last[v[i]])
        {
            bb.update(last[v[i]] + 1, -1);
        }
        bb.update(i, 1);
        last[v[i]] = i;
        while(j < q and qq[j].r == i)
        {
            res[qq[j].id] = bb.query(qq[j].r) - bb.query(qq[j].l - 1);
            j++;
        }

    }
    for(int i = 0; i < q; i++)
        cout << res[i] << endl;

}



int main()
{


    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int t = 1;
    // cin >> t;
    for(int i = 0; i < t; i++)
    {
        solve();
    }

}

Compiler output:
a.cc:12:23: error: 'N' is not a type
   12 |     std::vector<ll> b(N);
      |                       ^
a.cc: In member function 'void BIT::update(long long int, long long int)':
a.cc:18:14: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   18 |             b[id] += val;
      |              ^
a.cc: In member function 'long long int BIT::query(long long int)':
a.cc:28:21: error: invalid types '<unresolved overloaded function type>[long long int]' for array subscript
   28 |             ans += b[id];
      |                     ^
Language: C++

#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
using namespace std;
int main() {
	int N,Q;
	cin >> N >> Q;
	vector<int> C(N);
	vector<int> S(N);
	for (int i = 0; i < N; i++) {
		cin >> C.at(i);
	}
	vector<int> L(Q), R(Q);
	for (int i = 0; i < Q; i++) {
		cin >> L.at(i) >> R.at(i);
	}
	for (int i = 0; i < Q; i++) {
		set<int> A;
		for (int j = L.at(i) - 1; j < R.at(i) ; j++) {
			A.insert(C.at(j));
		}
		S.at(i) = A.size();
	}
	for (int i = 0; i < Q; i++) {
		cout << S.at(i) << endl;
	}
}


Compiler output:
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from a.cc:6:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:16:
/usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here
  132 |       struct _Vector_impl
      |              ^~~~~~~~~~~~
Language: C++

#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
#include <bit>
#include <bitset>
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <sstream>
#include <iostream>
#include <set>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <stdlib.h>
#include <queue>
#include <stack>
using namespace std;
int main() {
	int N,Q;
	cin >> N >> Q;
	vector<int> C(N);
	vector<int> S(N);
	for (int i = 0; i < N; i++) {
		cin >> C.at(i);
	}
	vector<int> L(Q), R(Q);
	for (int i = 0; i < Q; i++) {
		cin >> L.at(i) >> R.at(i);
	}
	for (int i = 0; i < Q; i++) {
		set<int> A;
		for (int j = L.at(i) - 1; j < R.at(i) ; j++) {
			A.insert(C.at(j));
		}
		S.at(i) = A.size();
	}
	for (int i = 0; i < Q; i++) {
		cout << S.at(i) << endl;
	}
}


Compiler output:
In file included from /usr/include/c++/14/string:43,
                 from /usr/include/c++/14/bitset:52,
                 from a.cc:7:
/usr/include/c++/14/bits/allocator.h: In destructor 'std::_Vector_base<int, std::allocator<int> >::_Vector_impl::~_Vector_impl()':
/usr/include/c++/14/bits/allocator.h:182:7: error: inlining failed in call to 'always_inline' 'std::allocator< <template-parameter-1-1> >::~allocator() noexcept [with _Tp = int]': target specific option mismatch
  182 |       ~allocator() _GLIBCXX_NOTHROW { }
      |       ^
In file included from /usr/include/c++/14/vector:66,
                 from a.cc:17:
/usr/include/c++/14/bits/stl_vector.h:132:14: note: called from here
  132 |       struct _Vector_impl
      |              ^~~~~~~~~~~~
Language: C++

#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
#define endl "\n"
#define sz(x) ((ll)(x).size())
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define prt(x) cout << (x)
#define prtl(x) cout << (x) << endl
#define rep(i,a,b) for(ll i=a; i<b; i++)
#define rrep(i,a,b) for(ll i=a; i>b; i--)
#define mp(a, b) make_pair(a, b)
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define debug(v) cout << #v<< ": " << v <<endl;
#define fst first
#define snd second
using namespace std;
using vi = vector<int>;
using vll = vector<long long int>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vc = vector<char>;
using vvi = vector<vector<int>>;
using vvll = vector<vector<long long int>>;
using vvc = vector<vector<char>>;
using ll = long long int;
using P = pair<long long int, long long int>;
using Map = map<long long int, long long int>;
ll INF = 1LL<<60;
ll M = 1000000007;
struct Mo
{
  vector< int > left, right, order;
  vector< bool > v;
  int width;
  int nl, nr, ptr;

  Mo(int n) : width((int) sqrt(n)), nl(0), nr(0), ptr(0), v(n) {}

  void insert(int l, int r) /* [l, r) */
  {
    left.push_back(l);
    right.push_back(r);
  }

  /* ソート */
  void build()
  {
    order.resize(left.size());
    iota(begin(order), end(order), 0);
    sort(begin(order), end(order), [&](int a, int b)
    {
      if(left[a] / width != left[b] / width) return left[a] < left[b];
      return right[a] < right[b];
    });
  }

  /* クエリを 1 つぶんすすめて, クエリのidを返す */
  int process()
  {
    if(ptr == order.size()) return (-1);
    const auto id = order[ptr];
    while(nl > left[id]) distribute(--nl);
    while(nr < right[id]) distribute(nr++);
    while(nl < left[id]) distribute(nl++);
    while(nr > right[id]) distribute(--nr);
    return (order[ptr++]);
  }

  inline void distribute(int idx)
  {
    v[idx].flip();
    if(v[idx]) add(idx);
    else del(idx);
  }

  void add(int idx);

  void del(int idx);
};

int N, A[500001], Q;
int ans[500001];
int cnt[500001], sum;

void Mo::add(int idx)
{
  if(cnt[A[idx]]++ == 0) ++sum;
}

void Mo::del(int idx)
{
  if(--cnt[A[idx]] == 0) --sum;
}

int main()
{
  cin >> N;
  cin >> Q;
  for(int i = 0; i < N; i++) {
    cin >> A[i];
  }
  Mo mo(N);
  for(int i = 0; i < Q; i++) {
    int a, b;
    cin >> a >> b;
    mo.insert(--a, b);
  }
  mo.build();
  for(int i = 0; i < Q; i++) {
      int g = mo.process()
    ans[g] = sum;
  }
  for(int i = 0; i < Q; i++) {
    prtl(ans[i]);
  }
}

Compiler output:
a.cc: In function 'int main()':
a.cc:112:5: error: expected ',' or ';' before 'ans'
  112 |     ans[g] = sum;
      |     ^~~
Language: Java

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;

public class EditorialMain {
    static final FS sc = new FS();  // 封装输入类
    static final PrintWriter pw = new PrintWriter(System.out);
    static int[] t;
    static int n, q;
    public static void main(String[] args) {
        n = sc.nextInt();
        q = sc.nextInt();
        int[] colors = new int[n];
        int[] lastPos = new int[n];
        Arrays.fill(lastPos, -1);
        int[] next = new int[n];
        Arrays.fill(next, -1);
        t = new int[n];
        for (int i = 0; i < n; i++) {
            colors[i] = sc.nextInt() - 1;
            if (lastPos[colors[i]] != -1) {
                next[lastPos[colors[i]]] = i;
            } else {
                add(i, 1);
            }
            lastPos[colors[i]] = i;
        }
        Query[] queries = new Query[q];
        for (int i = 0; i < q; i++) {
            queries[i] = new Query(sc.nextInt() - 1, sc.nextInt() - 1, i);
        }
        Arrays.sort(queries, Comparator.comparingInt(o -> o.from));
        int curFr = 0;
        int[] res = new int[q];
        for (Query query : queries) {
            while (curFr != query.from) {
                int ne = next[curFr];
                if (ne != -1) {
                    add(ne, 1);
                }
                add(curFr, -1);
                curFr++;
            }
            res[query.id] = get(query.to);
        }
        for (int x : res) {
            pw.println(x);
        }
        pw.flush();
    }

    static void add(int pos, int x) {
        for (; pos < n; pos |= pos + 1) {
            t[pos] += x;
        }
    }

    static int get(int pos) {
        int r = 0;
        for (; pos >= 0; pos = (pos & (pos + 1)) - 1) {
            r += t[pos];
        }
        return r;
    }

    static class Query {
        int from, to, id;
        public Query(int from, int to, int id) {
            this.from = from;
            this.to = to;
            this.id = id;
        }
    }

    static class FS {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer("");
        String next() {
            while(!st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch(Exception ignored) {}
            }
            return st.nextToken();
        }
        int[] nextArray(int n) {
            int[] a = new int[n];
            for(int i = 0;i < n;i++) {
                a[i] = nextInt();
            }
            return a;
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
    }
}

Compiler output:
Main.java:8: error: class EditorialMain is public, should be declared in a file named EditorialMain.java
public class EditorialMain {
       ^
1 error
Language: C++

#include <iostream>
#include <algorithm>
#include <cstdio>
#define f first
#define s second
 
using namespace std;
const int N=500009
pair <int, pair <int, int> > q[N];
int n, m, a[N], ans[N];
int st[5*N], used[5*N];
int cmp(pair <int, pair <int, int> > a, pair <int, pair <int, int> > b)
{
    if (a.s.f != b.s.f)
        return a.s.f < b.s.f;
    return a.f < b.f;
}
void update(int v, int l, int r, int x, int d)
{
    if (l == r)
    {
        st[v] = d;
        return;
    }
    int mid = (l + r) / 2;
    if (x <= mid)
        update(v * 2, l, mid, x, d);
    else
        update(v * 2 + 1, mid + 1, r, x, d);
    st[v] = st[v * 2] + st[v * 2 + 1];
}
int Find(int v, int A, int B, int l, int r)
{
    if (l > B || r < A)
        return 0;
    if (A == l && B == r)
        return st[v];
    int mid = (A + B) / 2;
    return Find(v * 2, A, mid, l, min(mid, r)) + Find(v * 2 + 1, mid + 1, B, max(mid + 1, l), r);
}
 
int main()
{
    scanf("%d", &n);
    scanf("%d", &m);
    for (int i = 1; i <= n; i++)
        scanf("%d", &a[i]);
    
    for (int i = 1; i <= m; i++)
        scanf("%d %d", &q[i].f, &q[i].s.f), q[i].s.s = i;
    sort(q + 1, q + m + 1, cmp);
    int j = 1;
    for (int i = 1; i <= m; i++)
    {
        while(j <= q[i].s.f)
        {
            if (!used[a[j]])
            {
                update(1, 1, n, j, 1);
                used[a[j]] = j;
            }
            else
            {
                update(1, 1, n, used[a[j]], 0);
                update(1, 1, n, j, 1);
                used[a[j]] = j;
            }
            j++;
        }
        ans[q[i].s.s] = Find(1, 1, n, q[i].f, q[i].s.f);
    }
    for (int i = 1; i <= m; i++)
        printf("%d\n", ans[i]);
 
    return 0;
}


Compiler output:
a.cc:9:1: error: expected ',' or ';' before 'pair'
    9 | pair <int, pair <int, int> > q[N];
      | ^~~~
a.cc: In function 'int main()':
a.cc:50:25: error: 'q' was not declared in this scope
   50 |         scanf("%d %d", &q[i].f, &q[i].s.f), q[i].s.s = i;
      |                         ^
a.cc:51:10: error: 'q' was not declared in this scope
   51 |     sort(q + 1, q + m + 1, cmp);
      |          ^