답안 #931711

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
931711 2024-02-22T09:53:15 Z pan 운세 보기 2 (JOI14_fortune_telling2) C++17
35 / 100
315 ms 262144 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//#include "bits_stdc++.h"
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
using namespace std;
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;
ll n, k, x, y,ans = 0;
ll const INF = 1e13;
vector<ll> activated;
bool compare(pii a, pii b)
{
	return activated[a.f]<activated[b.f];
}
struct node{

    int s, e, m; 
    ll val, summ; 
    ll lazy; 
    node *l, *r; 
	node (int S, int E)
	{ 
       s = S, e = E, m = (s+e)/2;
       val = 0; 
       lazy = 0; 
       summ = 0;
       l=r=nullptr;
 
    }
    void create()
    {
	   if(s != e && l==nullptr)
       { 
           l = new node(s, m); 
           r = new node(m+1, e); 
       }
    }
 
	void propogate()
	{
       if (lazy==0) return; 
       create();
       val+=lazy; 
       summ+=lazy*(e-s+1);
       if (s != e){ 
           l->lazy+=lazy;
           r->lazy+=lazy;
       }
       lazy=0; 
    }
	void update(int S, int E, ll V)
	{ 
	   propogate();
       if(s==S && e==E) lazy += V; 
       else{ 
           create();
           propogate();
           if(E <= m) l->update(S, E, V); 
           else if (m < S) r->update(S, E, V); 
           else l->update(S, m, V),r->update(m+1, E, V);
           l->propogate(),r->propogate();
           val = max(l->val, r->val); 
           summ = l-> summ+ r->summ;
       }
    }
	ll maxquery(int S, int E)
	{

       propogate(); 
       if(s == S && e == E) return val;
       create();
       if(E <= m) return l->maxquery(S, E); 
       else if(S >= m+1) return r->maxquery(S, E); 
       else return max(l->maxquery(S, m), r->maxquery(m+1, E)); 
   }
   	ll sumquery(int S, int E)
	{

       propogate(); 
       if(s == S && e == E) return summ;
       create();
       if(E <= m) return l->sumquery(S, E); 
       else if(S >= m+1) return r->sumquery(S, E); 
       else return l->sumquery(S, m) + r->sumquery(m+1, E); 
   }

} *root;

int main()
{
	ll n, q, x, y,ans = 0;
	input2(n, q);
	vector<pii> card;
	vector<pi> card2;
	vector<ll> queries(q+1);
	vector<ll> dum;
	activated.resize(n);
	for (ll i=0; i<n; ++i)
	{
		input2(x, y);
		if (x==y) {ans+=x; continue;} // does not matter
		if (x<y) {dum.pb(i);}
		else {swap(x,y);}
		card.pb(mp(i, mp(x,y)));
		card2.pb(mp(y, i));
		ans+=y;
		
	}
	sort(card2.begin(), card2.end());
	vector<ll> ind(n);
	for (ll i=0; i<card.size(); ++i) ind[card2[i].s] = i;
	n = card.size();
	root = new node(1, 1e9+5);
	map<ll,ll> m;
	for (ll i=1; i<=q; ++i) 
	{
		input(queries[i]);
		m[queries[i]] = i;
	}
	for (pi u: m) {root->update(u.f, u.f, u.s);}
	for (ll i=0; i<n; ++i) {activated[card[i].f] = root->maxquery(card[i].s.f, card[i].s.s-1); }
	sort(card.begin(), card.end(), compare);
	root = new node(0, n+5);
	ll slide = -1;
	for (ll u: dum) root->update(ind[u], ind[u], 1);
	for (ll i=1; i<=q; ++i)
	{
		ll in = ub(card2.begin(), card2.end(), mp(queries[i], INF))-card2.begin();
		if (in>=1) root->update(0, in-1, 1);
		while (slide+1<n && activated[card[slide+1].f]<=i)
		{
			slide++;
			if (activated[card[slide].f]==0) continue;
			if (root->sumquery(ind[card[slide].f], ind[card[slide].f])%2)
			{
				root->update(ind[card[slide].f], ind[card[slide].f], 1);
			}
		}
	}
	for (ll i=0; i<n; ++i)
	{
		if (root->sumquery(ind[card[i].f], ind[card[i].f])%2) ans+=card[i].s.f - card[i].s.s;
	}
	print(ans, '\n');
	
	
	
	return 0;
}

Compilation message

fortune_telling2.cpp: In function 'int main()':
fortune_telling2.cpp:133:16: warning: comparison of integer expressions of different signedness: 'll' {aka 'long long int'} and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  133 |  for (ll i=0; i<card.size(); ++i) ind[card2[i].s] = i;
      |               ~^~~~~~~~~~~~
fortune_telling2.cpp:12:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input2(x, y) scanf("%lld%lld", &x, &y);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:114:2: note: in expansion of macro 'input2'
  114 |  input2(n, q);
      |  ^~~~~~
fortune_telling2.cpp:12:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 | #define input2(x, y) scanf("%lld%lld", &x, &y);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~
fortune_telling2.cpp:122:3: note: in expansion of macro 'input2'
  122 |   input2(x, y);
      |   ^~~~~~
fortune_telling2.cpp:11:23: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 | #define input(x) scanf("%lld", &x);
      |                  ~~~~~^~~~~~~~~~~~
fortune_telling2.cpp:139:3: note: in expansion of macro 'input'
  139 |   input(queries[i]);
      |   ^~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3416 KB Output is correct
2 Correct 5 ms 5212 KB Output is correct
3 Correct 8 ms 7604 KB Output is correct
4 Correct 6 ms 7260 KB Output is correct
5 Correct 6 ms 7260 KB Output is correct
6 Correct 6 ms 7260 KB Output is correct
7 Correct 7 ms 7204 KB Output is correct
8 Correct 6 ms 6948 KB Output is correct
9 Correct 3 ms 3416 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 5 ms 5212 KB Output is correct
12 Correct 5 ms 5260 KB Output is correct
13 Correct 5 ms 5468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3416 KB Output is correct
2 Correct 5 ms 5212 KB Output is correct
3 Correct 8 ms 7604 KB Output is correct
4 Correct 6 ms 7260 KB Output is correct
5 Correct 6 ms 7260 KB Output is correct
6 Correct 6 ms 7260 KB Output is correct
7 Correct 7 ms 7204 KB Output is correct
8 Correct 6 ms 6948 KB Output is correct
9 Correct 3 ms 3416 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 5 ms 5212 KB Output is correct
12 Correct 5 ms 5260 KB Output is correct
13 Correct 5 ms 5468 KB Output is correct
14 Correct 60 ms 57660 KB Output is correct
15 Correct 125 ms 107464 KB Output is correct
16 Correct 193 ms 154484 KB Output is correct
17 Correct 254 ms 199804 KB Output is correct
18 Correct 249 ms 199520 KB Output is correct
19 Correct 259 ms 199188 KB Output is correct
20 Correct 247 ms 199188 KB Output is correct
21 Correct 226 ms 189428 KB Output is correct
22 Correct 75 ms 20864 KB Output is correct
23 Correct 70 ms 18296 KB Output is correct
24 Correct 71 ms 16248 KB Output is correct
25 Correct 70 ms 24300 KB Output is correct
26 Correct 167 ms 130804 KB Output is correct
27 Correct 195 ms 142616 KB Output is correct
28 Correct 176 ms 136700 KB Output is correct
29 Correct 214 ms 171120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 3416 KB Output is correct
2 Correct 5 ms 5212 KB Output is correct
3 Correct 8 ms 7604 KB Output is correct
4 Correct 6 ms 7260 KB Output is correct
5 Correct 6 ms 7260 KB Output is correct
6 Correct 6 ms 7260 KB Output is correct
7 Correct 7 ms 7204 KB Output is correct
8 Correct 6 ms 6948 KB Output is correct
9 Correct 3 ms 3416 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 5 ms 5212 KB Output is correct
12 Correct 5 ms 5260 KB Output is correct
13 Correct 5 ms 5468 KB Output is correct
14 Correct 60 ms 57660 KB Output is correct
15 Correct 125 ms 107464 KB Output is correct
16 Correct 193 ms 154484 KB Output is correct
17 Correct 254 ms 199804 KB Output is correct
18 Correct 249 ms 199520 KB Output is correct
19 Correct 259 ms 199188 KB Output is correct
20 Correct 247 ms 199188 KB Output is correct
21 Correct 226 ms 189428 KB Output is correct
22 Correct 75 ms 20864 KB Output is correct
23 Correct 70 ms 18296 KB Output is correct
24 Correct 71 ms 16248 KB Output is correct
25 Correct 70 ms 24300 KB Output is correct
26 Correct 167 ms 130804 KB Output is correct
27 Correct 195 ms 142616 KB Output is correct
28 Correct 176 ms 136700 KB Output is correct
29 Correct 214 ms 171120 KB Output is correct
30 Runtime error 315 ms 262144 KB Execution killed with signal 9
31 Halted 0 ms 0 KB -