Submission #28565369


Source Code Expand

/*
n, q = map(int, input().split())
a = list(map(int, input().split()))
d = dict()

for i in range(n):
    d[a[i]] = d.get(a[i], []) + [i+1]

for i in range(q):
    x, k = map(int, input().split())
    if d.get(x, -1) == -1:
        print(-1)
    elif len(d[x]) < k:
        print(-1)
    else:
        print(d[x][k-1])
*/

#include <iostream>
#include <vector>
#include <map>

int main(void){
    int n, q, x, k;
    vector<int> a(n);
    map<int, vactor<int>> d;

    std::cin >> n >> q;
    for (int i = 0; i < n; i++){
        std::cin >> a[i];
        if (d[a[i]] == 0){
            d[a[i]] = {}
        } else {
            d[a[i]].push_back(i+1);
        }
    }

    for (int i = 0; i < q; i++){
        std::cin >> x >> k;
        if (d[x] == 0){
            std::cout << -1 << std::endl;
        } else if (d[x].size() < k){
            std::cout << -1 << std::endl;
        } else:
        std::cout << d[x][k-1] << std::endl;
    }
}

Submission Info

Submission Time
Task C - The Kth Time Query
User ginji
Language C++ (GCC 9.2.1)
Score 0
Code Size 993 Byte
Status CE

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:25:5: error: ‘vector’ was not declared in this scope
   25 |     vector<int> a(n);
      |     ^~~~~~
./Main.cpp:25:5: note: suggested alternatives:
In file included from /usr/include/c++/9/vector:67,
                 from ./Main.cpp:20:
/usr/include/c++/9/bits/stl_vector.h:386:11: note:   ‘std::vector’
  386 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
In file included from ./Main.cpp:20:
/usr/include/c++/9/vector:90:13: note:   ‘std::pmr::vector’
   90 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
./Main.cpp:25:12: error: expected primary-expression before ‘int’
   25 |     vector<int> a(n);
      |            ^~~
./Main.cpp:26:5: error: ‘map’ was not declared in this scope
   26 |     map<int, vactor<int>> d;
      |     ^~~
./Main.cpp:26:5: note: suggested alternatives:
In file included from /usr/include/c++/9/map:61,
                 from ./Main.cpp:21:
/usr/include/c++/9/bits/stl_map.h:100:11: note:   ‘std::map’
  100 |     class map
      |           ^~~
In file included from ./Main.cpp:21:
/usr/include/c++/9/map:82:13: note:   ‘std::pmr::map’
   82 |       using map
      |             ^~~
./Main.cpp:26:9: error: expected primary-expression before ‘int’
   26 |     map<int, vactor<int>> d;
      |         ^~~
./Main.cpp:30:21: error: ‘a’ was not declared in this scope
   30 |         std::cin >> a[i];
      |                     ^
./Main.cpp:31:13: error: ‘d’ was not declared in this scope
   31 |         if (d[a[i]] == 0){
      |             ^
./Main.cpp:40:13: error: ‘d’ was not declared in this scope
   40 |         if (d[x] == 0){
      |             ^
./Main.cpp:44:15: error: expected primary-expression before ‘:’ token
   44 |         } else:
      |               ^