Submission #568010

#TimeUsernameProblemLanguageResultExecution timeMemory
568010josanneo22Street Lamps (APIO19_street_lamps)C++17
Compilation error
0 ms0 KiB
#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<stdlib.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b); i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)
 
#define mp make_pair
#define pb push_back
#define rsz resize
#define sz(x) int(x.size())
#define all(x) begin(x), end(x)
#define f first
#define s second
#define out(x) cout<<x<<'\n';
#define in(x) cin>>x;
#define inarr(a,x,y) for(int i=x;i<y;i++){cin>>a[i];}
#define incor(a,x,y) for(int i=x;i<y;i++){cin>>a[i].f>>a[i].s;}
int dx[4] = { -1, 0, 1, 0 };
int dy[4] = { 0, 1, 0, -1 };
const int mod = 1e9 + 7;

char change(char x)
{
	if(x=='0') return '1';
	return '0';
}
const int maxn= 3e5+3;
vi tim[maxn];
void solve()
{
	int n,q;
	cin>>n>>q;
	vpii queries(q);
	string ori;
	cin>>ori;
	FOR(i,0,n)
        tim[i].pb(mp(ori[i],0));
    FOR(i,0,q)
    {
        char x;cin>>x;
        if(x=="query")
        {
            int a,b;
            cin>>a>>b;
            pii temp=tim[a][sz(tim[a])-1];
            ll ans=0;
            if(temp.f=='0')
            {
                for(int j=sz(tim[a])-1;j>=0;j--)
                {
                    ans+=tim[a][j];
                }
            }
            else
            {
                ans+=(i-tim[a][sz(tim[a])-1]);
                for(int j=sz(tim[a])-2;j>=0;j--)
                {
                    ans+=tim[a][j];
                }
            }
            out(ans);
        }
        else
        {
            int x;
            in(x);
            if(change(ori[x])=='1')
                tim[x].pb(mp(ori[x],-i));
            else tim[x].pb(mp(ori[x],i));
            ori[x]=change(ori[x]);
        }
        
    }
}
int main()
{
	normal();
	int t=1;
	while(t--)
	{
		solve();
	}
	return 0;
}

Compilation message (stderr)

street_lamps.cpp: In function 'void solve()':
street_lamps.cpp:51:31: error: no matching function for call to 'std::vector<int>::push_back(std::pair<char, int>)'
   51 |         tim[i].pb(mp(ori[i],0));
      |                               ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from street_lamps.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from 'std::pair<char, int>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from 'std::pair<char, int>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
street_lamps.cpp:55:13: warning: comparison with string literal results in unspecified behavior [-Waddress]
   55 |         if(x=="query")
      |            ~^~~~~~~~~
street_lamps.cpp:55:13: error: ISO C++ forbids comparison between pointer and integer [-fpermissive]
street_lamps.cpp:59:41: error: conversion from '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} to non-scalar type 'pii' {aka 'std::pair<int, int>'} requested
   59 |             pii temp=tim[a][sz(tim[a])-1];
      |                                         ^
street_lamps.cpp:83:40: error: no matching function for call to 'std::vector<int>::push_back(std::pair<char, int>)'
   83 |                 tim[x].pb(mp(ori[x],-i));
      |                                        ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from street_lamps.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from 'std::pair<char, int>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from 'std::pair<char, int>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
street_lamps.cpp:84:40: error: no matching function for call to 'std::vector<int>::push_back(std::pair<char, int>)'
   84 |             else tim[x].pb(mp(ori[x],i));
      |                                        ^
In file included from /usr/include/c++/10/vector:67,
                 from /usr/include/c++/10/functional:62,
                 from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
                 from /usr/include/c++/10/algorithm:74,
                 from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:65,
                 from street_lamps.cpp:1:
/usr/include/c++/10/bits/stl_vector.h:1187:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(const value_type&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1187 |       push_back(const value_type& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1187:35: note:   no known conversion for argument 1 from 'std::pair<char, int>' to 'const value_type&' {aka 'const int&'}
 1187 |       push_back(const value_type& __x)
      |                 ~~~~~~~~~~~~~~~~~~^~~
/usr/include/c++/10/bits/stl_vector.h:1203:7: note: candidate: 'void std::vector<_Tp, _Alloc>::push_back(std::vector<_Tp, _Alloc>::value_type&&) [with _Tp = int; _Alloc = std::allocator<int>; std::vector<_Tp, _Alloc>::value_type = int]'
 1203 |       push_back(value_type&& __x)
      |       ^~~~~~~~~
/usr/include/c++/10/bits/stl_vector.h:1203:30: note:   no known conversion for argument 1 from 'std::pair<char, int>' to 'std::vector<int>::value_type&&' {aka 'int&&'}
 1203 |       push_back(value_type&& __x)
      |                 ~~~~~~~~~~~~~^~~
street_lamps.cpp: In function 'int main()':
street_lamps.cpp:92:2: error: 'normal' was not declared in this scope
   92 |  normal();
      |  ^~~~~~