답안 #479653

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
479653 2021-10-12T16:37:18 Z aris12345678 Poklon (COCI17_poklon) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
#define X first
#define Y second

const int mxN = 500005;
const int block = 800;
int cnt = 0;
int a[mxN], mp[mxN];

struct Q {
    int X, Y, pos;
};

bool comp(Q a, Q b) {
    if(a.X/block != b.X/block)
        return a.X/block < b.X/block;
    return a.Y < b.Y;
}

void add(int p) {
    if(mp[a[p]] == 2)
        cnt--;
    mp[a[p]]++;
    if(mp[a[p]] == 2)
        cnt++;
}

void remove(int p) {
    if(mp[a[p]] == 2)
        cnt--;
    mp[a[p]]--;
    if(mp[a[p]] == 2)
        cnt++;
}

int main() {
    int n, q;
    scanf("%d %d", &n, &q);
    map<int, int> m;
    for(int i = 1; i <= n; i++) {
        scanf("%d", &a[i]);
        m[a[i]]++;
    }
    int cc = 1;
    for(auto &x : m)
        m.Y = cc++;
    for(int i = 1; i <= n; i++)
        a[i] = m[a[i]];
    vector<Q> queries;
    for(int i = 0; i < q; i++) {
        int l, r;
        scanf("%d %d", &l, &r);
        queries.push_back({l, r, i});
    }
    sort(queries.begin(), queries.end(), comp);
    vector<int> ans(q);
    int ml = 1, mr = 0;
    for(int i = 0; i < q; i++) {
        int l = queries[i].X, r = queries[i].Y;
        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[queries[i].pos] = cnt;
    }
    for(int i = 0; i < q; i++)
        printf("%d\n", ans[i]);
    return 0;
}

Compilation message

poklon.cpp: In function 'int main()':
poklon.cpp:7:11: error: 'class std::map<int, int>' has no member named 'second'
    7 | #define Y second
      |           ^~~~~~
poklon.cpp:50:11: note: in expansion of macro 'Y'
   50 |         m.Y = cc++;
      |           ^
poklon.cpp:49:15: warning: unused variable 'x' [-Wunused-variable]
   49 |     for(auto &x : m)
      |               ^
poklon.cpp:42:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   42 |     scanf("%d %d", &n, &q);
      |     ~~~~~^~~~~~~~~~~~~~~~~
poklon.cpp:45:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   45 |         scanf("%d", &a[i]);
      |         ~~~~~^~~~~~~~~~~~~
poklon.cpp:56:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         scanf("%d %d", &l, &r);
      |         ~~~~~^~~~~~~~~~~~~~~~~