Submission #1065387

# Submission time Handle Problem Language Result Execution time Memory
1065387 2024-08-19T06:52:30 Z 김은성(#11116) Food Court (JOI21_foodcourt) C++17
0 / 100
847 ms 325972 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 3.1557e18;
ll mn[1<<19], mn2[1<<19], lazy1[1<<19], lazy2[1<<19];
void mergenode(int v){
	if(mn[2*v] < mn[2*v+1]){
		mn[v] = mn[2*v];
		mn2[v] = min(mn2[2*v], mn[2*v+1]);
	}
	else if(mn[2*v] > mn[2*v+1]){
		mn[v] = mn[2*v+1];
		mn2[v] = min(mn2[2*v+1], mn[2*v]);
	}
	else{
		mn[v] = mn[2*v];
		mn2[v] = min(mn2[2*v], mn2[2*v+1]);
	}
}
void propagate_lazy(int v, ll val){
	lazy1[2*v] = max(lazy1[2*v] + val, -mn[2*v]);
	lazy2[2*v] += val;
	lazy1[2*v+1] = max(lazy1[2*v+1] + val, -mn[2*v+1]);
	lazy2[2*v+1] += val;
}
void dolazy(int v, bool op){
	//assert(mn[v] < mn2[v]);
	if(mn[v] + lazy2[v] >= 0)
		mn[v] += lazy2[v];
	else
		mn[v] += lazy1[v];
	mn2[v] += lazy2[v];
	if(!op){
		lazy1[2*v] = max(lazy1[2*v] + lazy1[v], -mn[2*v]);
		lazy2[2*v] += lazy2[v];
		lazy1[2*v+1] = max(lazy1[2*v+1] + lazy1[v], -mn[2*v+1]);
		lazy2[2*v+1] += lazy2[v];
	}
	lazy1[v] = lazy2[v] =  0;
}
void update(int v, int l, int r, int s, int e, ll d){
	dolazy(v, l==r);
	if(e<l || r<s)
		return;
	if(s<=l && r<=e){
		if(l==r){
			mn[v] = max(mn[v] + d, 0ll);
			mn2[v] = INF;
			return;
		}
		else if(mn[v] > -d){
			mn[v] += d;
			mn2[v] += d;
			propagate_lazy(v, d);
			return;
		}
		else if(mn2[v] > -d){
			mn[v] = 0;
			mn2[v] += d;
			propagate_lazy(v, d);
			return;
		}
	}
	int mid = (l+r)/2;
	update(2*v, l, mid, s, e, d);
	update(2*v+1, mid+1, r, s, e, d);
	mergenode(v);
}
ll pointvalue(int v, int l, int r, int idx){
	dolazy(v, l==r);
	if(l==r)
		return mn[v];
	int mid = (l+r)/2;
	if(idx <= mid)
		return pointvalue(2*v, l, mid, idx);
	return pointvalue(2*v+1, mid+1, r, idx);
}
int main(){
	int n, m, q, i, t, type, l, r, c, a;
	ll k, b;
	scanf("%d %d %d", &n, &m, &q);
	//assert(m==1);
	memset(mn2, 63, sizeof(mn2));
	deque<int> qa[(const int)(n+1)];
	for(t=1; t<=q; t++){
		scanf("%d", &type);
		if(type==1){
			scanf("%d %d %d %lld", &l, &r, &c, &k);
			for(i=l; i<=r; i++)
				qa[i].push_back(c);
			update(1, 1, n, l, r, k);
		}
		else if(type==2){
			scanf("%d %d %lld", &l, &r, &k);
			for(i=l; i<=r; i++){
				if(!qa[i].empty())
					qa[i].pop_front();
			}
			update(1, 1, n, l, r, -k);
		}
		else{
			scanf("%d %lld", &a, &b);
			if(pointvalue(1, 1, n, a) >= b){
				printf("%d\n", qa[a][b-1]);
			}
			else
				printf("0\n");
		}
	}
	return 0;
}

Compilation message

foodcourt.cpp: In function 'int main()':
foodcourt.cpp:81:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |  scanf("%d %d %d", &n, &m, &q);
      |  ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:86:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   86 |   scanf("%d", &type);
      |   ~~~~~^~~~~~~~~~~~~
foodcourt.cpp:88:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   88 |    scanf("%d %d %d %lld", &l, &r, &c, &k);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:94:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   94 |    scanf("%d %d %lld", &l, &r, &k);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
foodcourt.cpp:102:9: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
  102 |    scanf("%d %lld", &a, &b);
      |    ~~~~~^~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 779 ms 54436 KB Output is correct
2 Correct 710 ms 55640 KB Output is correct
3 Correct 847 ms 55632 KB Output is correct
4 Correct 800 ms 55620 KB Output is correct
5 Correct 666 ms 55636 KB Output is correct
6 Correct 678 ms 55600 KB Output is correct
7 Incorrect 13 ms 9308 KB Output isn't correct
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 191 ms 325972 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 62 ms 103504 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7772 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 7772 KB Output isn't correct
2 Halted 0 ms 0 KB -