Submission #108841

# Submission time Handle Problem Language Result Execution time Memory
108841 2019-05-02T09:39:54 Z antimirage Two Dishes (JOI19_dishes) C++14
Compilation error
0 ms 0 KB
/**
	Elohim Essaim, Elohim Essaim I implore you...
**/
#include <bits/stdc++.h>
 
#define fr first
#define sc second
#define mk make_pair
#define pb push_back
#define all(s) s.begin(), s.end()
 
using namespace std;
 
const int N = 1e6 + 5;
 
int n, m, a[N], b[N], p[N], q[N];
 
long long ans, mx[N * 4], lz[N * 4], inf = 1e18, s[N], t[N], pr1[N], pr2[N];
 
map < pair<int, int>, long long> mp;
 
void push(int v, int tl, int tr){
	
	if (lz[v]){
		mx[v] += lz[v];
		
		if (tl != tr)
			lz[v + v] += lz[v],
			lz[v + v + 1] += lz[v];
			
		lz[v] = 0;
	}
}
 
void add (int l, int r, long long val, int v = 1, int tl = 0, int tr = n)
{
	push(v, tl, tr);
	
	if (l > tr || tl > r) return;
	
	if (l <= tl && tr <= r)
	{
		lz[v] = val;
		push(v, tl , tr);
		return;
	}
	int tm = (tl + tr) >> 1;
	
	add(l, r, val, v + v, tl, tm);
	add(l, r, val, v + v + 1, tm + 1, tr);
	
	mx[v] = max(mx[v + v], mx[v + v + 1]);
}
long long get (int l, int r, int v = 1, int tl = 0, int tr = n)
{
	push(v, tl, tr);
	if (l > tr || tl > r || l > r)
		return -inf;
		
	if (l <= tl && tr <= r)
		return mx[v];
	
	int tm = (tl + tr) >> 1;
	
	return max( get(l, r, v + v, tl, tm), get(l, r, v + v + 1, tm + 1, tr) );
}
void update (int pos, long long val, int v = 1, int tl = 0, int tr = n)
{
	push(v, tl, tr);
	
	if (tl == tr)
		mx[v] = max(mx[v], val);
	else{
		int tm = (tl + tr) >> 1;
		
		if (pos <= tm)
			update(pos, val, v + v, tl, tm);
		else
			update(pos, val, v + v + 1, tm + 1, tr);
			
		mx[v] = max( mx[v + v], mx[v + v + 1] );
	}
}
main(){
	cin >> n >> m;
	
	for (int i = 1; i <= n; i++){
		
		scanf("%d%lld%d", &a[i], &s[i], &p[i]);
		pr1[i] = pr1[i - 1] + a[i];
	}	
	for (int i = 1; i <= m; i++){
		
		scanf("%d%lld%d", &b[i], &t[i], &q[i]);
		pr2[i] = pr2[i - 1] + b[i];
	}
	for (int i = 1; i <= n; i++)
	{
		if (pr1[i] > s[i]) continue;
		
		
		if ( pr1[i] + pr2[m] <= s[i] ) {
			ans += p[i];
			continue;
		}
		
		int j = upper_bound( pr2 + 1, pr2 + 1 + m, s[i] - pr1[i] ) - pr2 - 1;
		
		mp[ mk(j, -i) ] += p[i];
	}	
	for (int i = 1; i <= m; i++)
	{
		if (pr2[i] > t[i]) continue;
		
		ans += q[i];
		
		if ( pr2[i] + pr1[n] <= t[i] ) {
			continue;	
		}
		
		int j = upper_bound( pr1 + 1, pr1 + 1 + n, t[i] - pr2[i] ) - pr1 - 1;
		
		mp[ mk(i - 1, -j - 1) ] -= q[i];
	}
	for (auto it : mp)
	{
		update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
		
		add( -it.fr.sc, n, it.sc);
	}
	cout << mx[1] + ans << endl;
}
/**
11
10
10 15 80
55 28 -91
12 6 52
43 64 18
59 95 -57
59 77 57
56 68 -77
73 82 -95
44 59 -88
62 49 18
29 10 -2
35 62 28
76 81 -2
5 71 -50
53 31 36
84 96 89
48 10 -22
15 82 -38
56 64 -51
4 70 -48
10 9 -63

**/

Compilation message

dishes.cpp:84:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main(){
      ^
dishes.cpp: In function 'int main()':
dishes.cpp:127:41: error: no matching function for call to 'get(int)'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
dishes.cpp:54:11: note: candidate: long long int get(int, int, int, int, int)
 long long get (int l, int r, int v = 1, int tl = 0, int tr = n)
           ^~~
dishes.cpp:54:11: note:   candidate expects 5 arguments, 1 provided
In file included from /usr/include/c++/7/functional:54:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from dishes.cpp:4:
/usr/include/c++/7/tuple:1361:5: note: candidate: template<class _Tp, class ... _Types> constexpr const _Tp& std::get(const std::tuple<_Elements ...>&)
     get(const tuple<_Types...>& __t) noexcept
     ^~~
/usr/include/c++/7/tuple:1361:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'const std::tuple<_Elements ...>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/functional:54:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from dishes.cpp:4:
/usr/include/c++/7/tuple:1355:5: note: candidate: template<class _Tp, class ... _Types> constexpr _Tp&& std::get(std::tuple<_Elements ...>&&)
     get(tuple<_Types...>&& __t) noexcept
     ^~~
/usr/include/c++/7/tuple:1355:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'std::tuple<_Elements ...>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/functional:54:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from dishes.cpp:4:
/usr/include/c++/7/tuple:1349:5: note: candidate: template<class _Tp, class ... _Types> constexpr _Tp& std::get(std::tuple<_Elements ...>&)
     get(tuple<_Types...>& __t) noexcept
     ^~~
/usr/include/c++/7/tuple:1349:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'std::tuple<_Elements ...>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/functional:54:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from dishes.cpp:4:
/usr/include/c++/7/tuple:1326:5: note: candidate: template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >&& std::get(std::tuple<_Elements ...>&&)
     get(tuple<_Elements...>&& __t) noexcept
     ^~~
/usr/include/c++/7/tuple:1326:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'std::tuple<_Elements ...>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/functional:54:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from dishes.cpp:4:
/usr/include/c++/7/tuple:1320:5: note: candidate: template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(const std::tuple<_Elements ...>&)
     get(const tuple<_Elements...>& __t) noexcept
     ^~~
/usr/include/c++/7/tuple:1320:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'const std::tuple<_Elements ...>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/functional:54:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from dishes.cpp:4:
/usr/include/c++/7/tuple:1314:5: note: candidate: template<long unsigned int __i, class ... _Elements> constexpr std::__tuple_element_t<__i, std::tuple<_Elements ...> >& std::get(std::tuple<_Elements ...>&)
     get(tuple<_Elements...>& __t) noexcept
     ^~~
/usr/include/c++/7/tuple:1314:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'std::tuple<_Elements ...>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/tuple:39:0,
                 from /usr/include/c++/7/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from dishes.cpp:4:
/usr/include/c++/7/array:324:5: note: candidate: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr const _Tp& std::get(const std::array<_Tp, _Nm>&)
     get(const array<_Tp, _Nm>& __arr) noexcept
     ^~~
/usr/include/c++/7/array:324:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'const std::array<_Tp, _Nm>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/tuple:39:0,
                 from /usr/include/c++/7/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from dishes.cpp:4:
/usr/include/c++/7/array:316:5: note: candidate: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp&& std::get(std::array<_Tp, _Nm>&&)
     get(array<_Tp, _Nm>&& __arr) noexcept
     ^~~
/usr/include/c++/7/array:316:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'std::array<_Tp, _Nm>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/tuple:39:0,
                 from /usr/include/c++/7/functional:54,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:71,
                 from dishes.cpp:4:
/usr/include/c++/7/array:307:5: note: candidate: template<long unsigned int _Int, class _Tp, long unsigned int _Nm> constexpr _Tp& std::get(std::array<_Tp, _Nm>&)
     get(array<_Tp, _Nm>& __arr) noexcept
     ^~~
/usr/include/c++/7/array:307:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'std::array<_Tp, _Nm>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from dishes.cpp:4:
/usr/include/c++/7/utility:273:5: note: candidate: template<class _Tp, class _Up> constexpr _Tp&& std::get(std::pair<_Up, _Tp>&&)
     get(pair<_Up, _Tp>&& __p) noexcept
     ^~~
/usr/include/c++/7/utility:273:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'std::pair<_Up, _Tp>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from dishes.cpp:4:
/usr/include/c++/7/utility:268:5: note: candidate: template<class _Tp, class _Up> constexpr const _Tp& std::get(const std::pair<_Up, _Tp>&)
     get(const pair<_Up, _Tp>& __p) noexcept
     ^~~
/usr/include/c++/7/utility:268:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'const std::pair<_Up, _Tp>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from dishes.cpp:4:
/usr/include/c++/7/utility:263:5: note: candidate: template<class _Tp, class _Up> constexpr _Tp& std::get(std::pair<_Up, _Tp>&)
     get(pair<_Up, _Tp>& __p) noexcept
     ^~~
/usr/include/c++/7/utility:263:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'std::pair<_Up, _Tp>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from dishes.cpp:4:
/usr/include/c++/7/utility:258:5: note: candidate: template<class _Tp, class _Up> constexpr _Tp&& std::get(std::pair<_T1, _T2>&&)
     get(pair<_Tp, _Up>&& __p) noexcept
     ^~~
/usr/include/c++/7/utility:258:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'std::pair<_T1, _T2>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from dishes.cpp:4:
/usr/include/c++/7/utility:253:5: note: candidate: template<class _Tp, class _Up> constexpr const _Tp& std::get(const std::pair<_T1, _T2>&)
     get(const pair<_Tp, _Up>& __p) noexcept
     ^~~
/usr/include/c++/7/utility:253:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'const std::pair<_T1, _T2>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from dishes.cpp:4:
/usr/include/c++/7/utility:248:5: note: candidate: template<class _Tp, class _Up> constexpr _Tp& std::get(std::pair<_T1, _T2>&)
     get(pair<_Tp, _Up>& __p) noexcept
     ^~~
/usr/include/c++/7/utility:248:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'std::pair<_T1, _T2>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from dishes.cpp:4:
/usr/include/c++/7/utility:239:5: note: candidate: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr const typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(const std::pair<_Tp1, _Tp2>&)
     get(const std::pair<_Tp1, _Tp2>& __in) noexcept
     ^~~
/usr/include/c++/7/utility:239:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'const std::pair<_Tp1, _Tp2>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from dishes.cpp:4:
/usr/include/c++/7/utility:234:5: note: candidate: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type&& std::get(std::pair<_Tp1, _Tp2>&&)
     get(std::pair<_Tp1, _Tp2>&& __in) noexcept
     ^~~
/usr/include/c++/7/utility:234:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'std::pair<_Tp1, _Tp2>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
In file included from /usr/include/c++/7/algorithm:60:0,
                 from /usr/include/x86_64-linux-gnu/c++/7/bits/stdc++.h:65,
                 from dishes.cpp:4:
/usr/include/c++/7/utility:229:5: note: candidate: template<long unsigned int _Int, class _Tp1, class _Tp2> constexpr typename std::tuple_element<_Int, std::pair<_Tp1, _Tp2> >::type& std::get(std::pair<_Tp1, _Tp2>&)
     get(std::pair<_Tp1, _Tp2>& __in) noexcept
     ^~~
/usr/include/c++/7/utility:229:5: note:   template argument deduction/substitution failed:
dishes.cpp:127:41: note:   mismatched types 'std::pair<_Tp1, _Tp2>' and 'int'
   update( -it.fr.sc, get((-it.fr.sc) - 1), (-it.fr.sc) - 1) );
                                         ^
dishes.cpp:89:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld%d", &a[i], &s[i], &p[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:94:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld%d", &b[i], &t[i], &q[i]);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~