编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#80254 | #1021. jwp的区间游戏 | Compile Error | 0 | 0 ms | 0 K | C++ 17 / 1.2 K | BenChak | 2022-07-16 18:24:06 |
#include <stdio.h>
#include <algorithm>
using namespace std;
struct map {
int no, go, h;
} a[1000005];
int n, ans, p;
bool end[1000005];
bool cmp(map a, map b) { return a.go < b.go; }
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
scanf("%d%d", &a[i].no, &a[i].go);
}
sort(a + 1, a + n + 1, cmp);
for (int i = 1; i <= n; ++i) {
if (p <= a[i].no && end[i] == 0) {
for (int j = 1; j <= n; ++j) {
if (end[j] == 0 && a[i].go >= a[j].no)
end[j] = 1;
}
p = a[i].go;
++ans;
}
}
printf("%lld", ans);
return 0;
}
#include <stdio.h>
#include <algorithm>
using namespace std;
struct map {
int no, go, ID;
} a[1000005], b[1000005];
bool s[1000005];
long long int n, ans, p = -1;
bool cmp(map a, map b) { return a.go < b.go; }
bool cmp1(map c, map d) { return c.no < d.no; }
int main() {
scanf("%lld", &n);
for (int i = 1; i <= n; ++i) {
a[i].ID = i;
b[i].ID = i;
scanf("%lld%lld", &a[i].no, &a[i].go);
b[i].no = a[i].no;
b[i].go = a[i].go;
}
sort(a + 1, a + n + 1, cmp);
sort(b + 1, b + n + 1, cmp1);
for (int i = 1; i <= n; ++i) {
if (p <= a[i].no && s[i] == 0) {
if (s[a[i].ID] == 0) {
if (s[j] == 0 && a[i].go >= a[j].no)
s[j] = 1;
}
// for(int j=1;j<=n;++j)
// {
// }
p = a[i].go;
++ans;
}
}
printf("%lld", ans);
return 0;
}
编译信息
/sandbox/1/a.cpp:36:2: error: stray '#' in program
36 | }#include<stdio.h>
| ^
/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:23:18: error: reference to 'end' is ambiguous
23 | if(p<=a[i].no&&end[i]==0)
| ^~~
In file included from /usr/include/c++/10/array:41,
from /usr/include/c++/10/tuple:39,
from /usr/include/c++/10/functional:54,
from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
from /usr/include/c++/10/algorithm:74,
from /sandbox/1/a.cpp:2:
/usr/include/c++/10/bits/range_access.h:110:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)'
110 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
| ^~~
/usr/include/c++/10/bits/range_access.h:109:31: note: 'template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)'
109 | template<typename _Tp> _Tp* end(valarray<_Tp>&);
| ^~~
/usr/include/c++/10/bits/range_access.h:100:5: note: 'template<class _Tp, unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
100 | end(_Tp (&__arr)[_Nm])
| ^~~
/usr/include/c++/10/bits/range_access.h:81:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
81 | end(const _Container& __cont) -> decltype(__cont.end())
| ^~~
/usr/include/c++/10/bits/range_access.h:71:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
71 | end(_Container& __cont) -> decltype(__cont.end())
| ^~~
In file included from /usr/include/c++/10/utility:76,
from /usr/include/c++/10/algorithm:60,
from /sandbox/1/a.cpp:2:
/usr/include/c++/10/initializer_list:101:5: note: 'template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)'
101 | end(initializer_list<_Tp> __ils) noexcept
| ^~~
/sandbox/1/a.cpp:8:6: note: 'bool end [1000005]'
8 | bool end[1000005];
| ^~~
/sandbox/1/a.cpp:27:8: error: reference to 'end' is ambiguous
27 | if(end[j]==0&&a[i].go>=a[j].no)
| ^~~
In file included from /usr/include/c++/10/array:41,
from /usr/include/c++/10/tuple:39,
from /usr/include/c++/10/functional:54,
from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
from /usr/include/c++/10/algorithm:74,
from /sandbox/1/a.cpp:2:
/usr/include/c++/10/bits/range_access.h:110:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)'
110 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
| ^~~
/usr/include/c++/10/bits/range_access.h:109:31: note: 'template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)'
109 | template<typename _Tp> _Tp* end(valarray<_Tp>&);
| ^~~
/usr/include/c++/10/bits/range_access.h:100:5: note: 'template<class _Tp, unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
100 | end(_Tp (&__arr)[_Nm])
| ^~~
/usr/include/c++/10/bits/range_access.h:81:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
81 | end(const _Container& __cont) -> decltype(__cont.end())
| ^~~
/usr/include/c++/10/bits/range_access.h:71:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
71 | end(_Container& __cont) -> decltype(__cont.end())
| ^~~
In file included from /usr/include/c++/10/utility:76,
from /usr/include/c++/10/algorithm:60,
from /sandbox/1/a.cpp:2:
/usr/include/c++/10/initializer_list:101:5: note: 'template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)'
101 | end(initializer_list<_Tp> __ils) noexcept
| ^~~
/sandbox/1/a.cpp:8:6: note: 'bool end [1000005]'
8 | bool end[1000005];
| ^~~
/sandbox/1/a.cpp:28:5: error: reference to 'end' is ambiguous
28 | end[j]=1;
| ^~~
In file included from /usr/include/c++/10/array:41,
from /usr/include/c++/10/tuple:39,
from /usr/include/c++/10/functional:54,
from /usr/include/c++/10/pstl/glue_algorithm_defs.h:13,
from /usr/include/c++/10/algorithm:74,
from /sandbox/1/a.cpp:2:
/usr/include/c++/10/bits/range_access.h:110:37: note: candidates are: 'template<class _Tp> const _Tp* std::end(const std::valarray<_Tp>&)'
110 | template<typename _Tp> const _Tp* end(const valarray<_Tp>&);
| ^~~
/usr/include/c++/10/bits/range_access.h:109:31: note: 'template<class _Tp> _Tp* std::end(std::valarray<_Tp>&)'
109 | template<typename _Tp> _Tp* end(valarray<_Tp>&);
| ^~~
/usr/include/c++/10/bits/range_access.h:100:5: note: 'template<class _Tp, unsigned int _Nm> constexpr _Tp* std::end(_Tp (&)[_Nm])'
100 | end(_Tp (&__arr)[_Nm])
| ^~~
/usr/include/c++/10/bits/range_access.h:81:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(const _Container&)'
81 | end(const _Container& __cont) -> decltype(__cont.end())
| ^~~
/usr/include/c++/10/bits/range_access.h:71:5: note: 'template<class _Container> constexpr decltype (__cont.end()) std::end(_Container&)'
71 | end(_Container& __cont) -> decltype(__cont.end())
| ^~~
In file included from /usr/include/c++/10/utility:76,
from /usr/include/c++/10/algorithm:60,
from /sandbox/1/a.cpp:2:
/usr/include/c++/10/initializer_list:101:5: note: 'template<class _Tp> constexpr const _Tp* std::end(std::initializer_list<_Tp>)'
101 | end(initializer_list<_Tp> __ils) noexcept
| ^~~
/sandbox/1/a.cpp:8:6: note: 'bool end [1000005]'
8 | bool end[1000005];
| ^~~
/sandbox/1/a.cpp:34:13: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
34 | printf("%lld",ans);
| ~~~^ ~~~
| | |
| | int
| long long int
| %d
/sandbox/1/a.cpp: At global scope:
/sandbox/1/a.cpp:36:3: error: 'include' does not name a type
36 | }#include<stdio.h>
| ^~~~~~~
/sandbox/1/a.cpp:39:8: error: redefinition of 'struct map'
39 | struct map{
| ^~~
/sandbox/1/a.cpp:4:8: note: previous definition of 'struct map'
4 | struct map{
| ^~~
/sandbox/1/a.cpp:41:2: error: conflicting declaration 'int a [1000005]'
41 | }a[1000005],b[1000005];
| ^
/sandbox/1/a.cpp:6:2: note: previous declaration as 'map a [1000005]'
6 | }a[1000005];
| ^
/sandbox/1/a.cpp:43:15: error: conflicting declaration 'long long int n'
43 | long long int n,ans,p=-1;
| ^
/sandbox/1/a.cpp:7:5: note: previous declaration as 'int n'
7 | int n,ans,p;
| ^
/sandbox/1/a.cpp:43:17: error: conflicting declaration 'long long int ans'
43 | long long int n,ans,p=-1;
| ^~~
/sandbox/1/a.cpp:7:7: note: previous declaration as 'int ans'
7 | int n,ans,p;
| ^~~
/sandbox/1/a.cpp:43:21: error: conflicting declaration 'long long int p'
43 | long long int n,ans,p=-1;
| ^
/sandbox/1/a.cpp:7:11: note: previous declaration as 'int p'
7 | int n,ans,p;
| ^
/sandbox/1/a.cpp:44:6: error: redefinition of 'bool cmp(map, map)'
44 | bool cmp(map a,map b)
| ^~~
/sandbox/1/a.cpp:9:6: note: 'bool cmp(map, map)' previously defined here
9 | bool cmp(map a,map b)
| ^~~
/sandbox/1/a.cpp:52:5: error: redefinition of 'int main()'
52 | int main()
| ^~~~
/sandbox/1/a.cpp:13:5: note: 'int main()' previously defined here
13 | int main()
| ^~~~
/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:54:12: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
54 | scanf("%lld",&n);
| ~~~^ ~~
| | |
| | int*
| long long int*
| %d
/sandbox/1/a.cpp:57:8: error: 'struct map' has no member named 'ID'
57 | a[i].ID=i;
| ^~
/sandbox/1/a.cpp:58:8: error: request for member 'ID' in 'b[i]', which is of non-class type 'int'
58 | b[i].ID=i;
| ^~
/sandbox/1/a.cpp:59:13: warning: format '%lld' expects argument of type 'long long int*', but argument 2 has type 'int*' [-Wformat=]
59 | scanf("%lld%lld",&a[i].no,&a[i].go);
| ~~~^ ~~~~~~~~
| | |
| | int*
| long long int*
| %d
/sandbox/1/a.cpp:59:17: warning: format '%lld' expects argument of type 'long long int*', but argument 3 has type 'int*' [-Wformat=]
59 | scanf("%lld%lld",&a[i].no,&a[i].go);
| ~~~^ ~~~~~~~~
| | |
| | int*
| long long int*
| %d
/sandbox/1/a.cpp:60:8: error: request for member 'no' in 'b[i]', which is of non-class type 'int'
60 | b[i].no=a[i].no;
| ^~
/sandbox/1/a.cpp:61:8: error: request for member 'go' in 'b[i]', which is of non-class type 'int'
61 | b[i].go=a[i].go;
| ^~
/sandbox/1/a.cpp:69:14: error: 'struct map' has no member named 'ID'
69 | if(s[a[i].ID]==0)
| ^~
/sandbox/1/a.cpp:71:10: error: 'j' was not declared in this scope
71 | if(s[j]==0&&a[i].go>=a[j].no)
| ^
/sandbox/1/a.cpp:82:13: warning: format '%lld' expects argument of type 'long long int', but argument 2 has type 'int' [-Wformat=]
82 | printf("%lld",ans);
| ~~~^ ~~~
| | |
| | int
| long long int
| %d
In file included from /usr/include/c++/10/bits/stl_algobase.h:71,
from /usr/include/c++/10/algorithm:61,
from /sandbox/1/a.cpp:2:
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'constexpr bool __gnu_cxx::__ops::_Iter_comp_iter<_Compare>::operator()(_Iterator1, _Iterator2) [with _Iterator1 = int*; _Iterator2 = int*; _Compare = bool (*)(map, map)]':
/usr/include/c++/10/bits/stl_algo.h:82:17: required from 'void std::__move_median_to_first(_Iterator, _Iterator, _Iterator, _Iterator, _Compare) [with _Iterator = int*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:1924:34: required from '_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:1958:38: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = int*; _Size = int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:1974:25: required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:4892:18: required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = int*; _Compare = bool (*)(map, map)]'
/sandbox/1/a.cpp:64:21: required from here
/usr/include/c++/10/bits/predefined_ops.h:156:30: error: could not convert '* __it1' from 'int' to 'map'
156 | { return bool(_M_comp(*__it1, *__it2)); }
| ~~~~~~~^~~~~~~~~~~~~~~~
| |
| int
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Val_comp_iter<_Compare>::operator()(_Value&, _Iterator) [with _Value = int; _Iterator = int*; _Compare = bool (*)(map, map)]':
/usr/include/c++/10/bits/stl_algo.h:1826:20: required from 'void std::__unguarded_linear_insert(_RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Val_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:1854:36: required from 'void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:1886:25: required from 'void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:1977:31: required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:4892:18: required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = int*; _Compare = bool (*)(map, map)]'
/sandbox/1/a.cpp:64:21: required from here
/usr/include/c++/10/bits/predefined_ops.h:238:23: error: could not convert '__val' from 'int' to 'map'
238 | { return bool(_M_comp(__val, *__it)); }
| ~~~~~~~^~~~~~~~~~~~~~
| |
| int
/usr/include/c++/10/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_comp_val<_Compare>::operator()(_Iterator, _Value&) [with _Iterator = int*; _Value = int; _Compare = bool (*)(map, map)]':
/usr/include/c++/10/bits/stl_heap.h:139:48: required from 'void std::__push_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare&) [with _RandomAccessIterator = int*; _Distance = int; _Tp = int; _Compare = __gnu_cxx::__ops::_Iter_comp_val<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_heap.h:246:23: required from 'void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp, _Compare) [with _RandomAccessIterator = int*; _Distance = int; _Tp = int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_heap.h:355:22: required from 'void std::__make_heap(_RandomAccessIterator, _RandomAccessIterator, _Compare&) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:1666:23: required from 'void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:1937:25: required from 'void std::__partial_sort(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:1953:27: required from 'void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size, _Compare) [with _RandomAccessIterator = int*; _Size = int; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:1974:25: required from 'void std::__sort(_RandomAccessIterator, _RandomAccessIterator, _Compare) [with _RandomAccessIterator = int*; _Compare = __gnu_cxx::__ops::_Iter_comp_iter<bool (*)(map, map)>]'
/usr/include/c++/10/bits/stl_algo.h:4892:18: required from 'void std::sort(_RAIter, _RAIter, _Compare) [with _RAIter = int*; _Compare = bool (*)(map, map)]'
/sandbox/1/a.cpp:64:21: required from here
/usr/include/c++/10/bits/predefined_ops.h:194:23: error: could not convert '* __it' from 'int' to 'map'
194 | { return bool(_M_comp(*__it, __val)); }
| ~~~~~~~^~~~~~~~~~~~~~
| |
| int
/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:15:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
15 | scanf("%d",&n);
| ~~~~~^~~~~~~~~
/sandbox/1/a.cpp:18:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | scanf("%d%d",&a[i].no,&a[i].go);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
/sandbox/1/a.cpp: In function 'int main()':
/sandbox/1/a.cpp:54:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | scanf("%lld",&n);
| ~~~~~^~~~~~~~~~~
/sandbox/1/a.cpp:59:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
59 | scanf("%lld%lld",&a[i].no,&a[i].go);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~