답안 #260510

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
260510 2020-08-10T12:26:32 Z sckmd Poklon (COCI17_poklon) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>

using namespace std;
#define MAXN 500005
int a[MAXN];
map <int,int> mp;
int hsh = 0;
int ans[MAXN];

struct que
{
  int l,r,id;
};
que queries[MAXN];
int BLOCK;
int cnt[MAXN];

bool cmp(que qa,que qb)
{
  if(qa.l/BLOCK != qb.l/BLOCK)return qa.l < qb.l;
  return qa.r < qb.r;
}

int res = 0;

void chk1(int br)
{
  //++
  if(cnt[br]==2)res++;
  if(cnt[br]==3)res--;
}
void chk2(int br)
{
  //--
  if(cnt[br]==2)res++;
  if(cnt[br]==1)res--;
}

int main()
{
  ios_base::sync_with_stdio(false);
  int n,q;
  BLOCK = sqrt(n);
  cin >> n >> q;
  for(int i = 1; i <= n; i++)
  {
	cin >> a[i];
    if(!mp[a[i]])mp[a[i]]=++hsh;
    a[i]=mp[a[i]];
  }
  for(int i = 0; i < q; i++)cin >> queries[i].l >> queries[i].r,queries[i].id=i;
  sort(queries,queries+q,cmp);
  int L = 1;
  int R = n;
  for(int i = 1; i <= n; i++)cnt[a[i]]++;
  for(int i = 1; i <= n; i++)if(cnt[i]==2)res++;
  for(int i = 0; i < q; i++)
  {
    int l = queries[i].l;
    int r = queries[i].r;
    int idx = queries[i].idx;
    while(L < l)cnt[a[L]]--,L++,chk2();
    while(L > l)L--,cnt[a[L]]++,chk1();
    while(R > r)cnt[a[R]]--,R--,chk2();
    while(R < r)R++,cnt[a[R]]++,chk1();
    ans[idx]=res;
  }
  for(int i = 0; i < q; i++)cout << ans[i] << "\n";
  return 0;
}

Compilation message

poklon.cpp: In function 'int main()':
poklon.cpp:61:26: error: 'struct que' has no member named 'idx'; did you mean 'id'?
     int idx = queries[i].idx;
                          ^~~
                          id
poklon.cpp:62:38: error: too few arguments to function 'void chk2(int)'
     while(L < l)cnt[a[L]]--,L++,chk2();
                                      ^
poklon.cpp:32:6: note: declared here
 void chk2(int br)
      ^~~~
poklon.cpp:63:38: error: too few arguments to function 'void chk1(int)'
     while(L > l)L--,cnt[a[L]]++,chk1();
                                      ^
poklon.cpp:26:6: note: declared here
 void chk1(int br)
      ^~~~
poklon.cpp:64:38: error: too few arguments to function 'void chk2(int)'
     while(R > r)cnt[a[R]]--,R--,chk2();
                                      ^
poklon.cpp:32:6: note: declared here
 void chk2(int br)
      ^~~~
poklon.cpp:65:38: error: too few arguments to function 'void chk1(int)'
     while(R < r)R++,cnt[a[R]]++,chk1();
                                      ^
poklon.cpp:26:6: note: declared here
 void chk1(int br)
      ^~~~