답안 #927977

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
927977 2024-02-15T15:40:37 Z pan 말 (IOI15_horses) C++17
100 / 100
545 ms 119892 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 const mod = 1e9+7;
ll n;
vector<ll> x, y;
 
ll inv(ll a) {
  return a <= 1 ? a : mod - (long long)(mod/a) * inv(mod % a) % mod;
}
struct node{
    int s, e, m; //range is [s,e], m is the middle point
    ll val, lazy;
    ld logval, loglazy; //lazy tag of [s,e]
    node *l, *r; //create two children l and r, where l is [s,m] and [m+1,e]
    node (int S, int E){ //constructor called node
       s = S, e = E, m = (s+e)/2;
       val = 1; logval = 0; //initially all values are 0
       lazy = 1; loglazy = (ld) 0.0; //lazy tag of 0 will mean there is no update (sentinel value)
       if(s != e){ //node is not yet a leaf, so create two children
		     l = new node(s, m); //create left child
             r = new node(m+1, e); //create right child
		}
 
	}
    void propogate(){
       if (lazy==1 && loglazy == 0) return; //nothing happens
       val = (val*lazy)%mod;//(e-s+1) is the length of the range
       logval+=loglazy;
       if (s != e){ //not a leaf, send lazy tags to children
           l->lazy = (l->lazy*lazy)%mod;
           r->lazy = (r->lazy*lazy)%mod;
           l->loglazy+=loglazy;
           r->loglazy+=loglazy;
       }
       lazy=1; //set our lazy tag value back to the sentinel
       loglazy = 0;
    }
    void update(int S, int E, ll V, ld logv){ //increment [S,E] by V
       if(s==S && e==E)//update covers range, update lazy tag
       {
		   lazy = (lazy*(V))%mod;
		   loglazy += logv;
	   }
       else{ //go we have to go deeper
           if(E <= m) l->update(S, E, V, logv); //[S,E] is in the left child
           else if (m < S) r->update(S, E, V, logv); //[S,E] is in the right child
           else l->update(S, m, V, logv),r->update(m+1, E, V, logv);
           l->propogate(),r->propogate();
           //remember to propogate your children before update yourself
		   if (l-> logval>r->logval)
		   {
			   logval = l-> logval;
			   val = l-> val;
			   
		   }
		   else
		   {
			   logval = r->logval;
			   val = r->val;
		   }
       }
    }
 
} *root;
 
 
int init(int N, int X[], int Y[])
{
	root = new node(0, N);
	n=N;
	x.resize(n); y.resize(n);
	for (ll i=0; i<n; ++i) x[i] = X[i];
	for (ll i=0; i<n; ++i) y[i] = Y[i];
	ll val = 1;
	ld logval = 0.0;
	for (ll i=0; i<n; ++i)
	{
		val = (val*X[i])%mod;
		logval+=logl(X[i]);
		root->update(i, i, (val*(Y[i]%mod))%mod, logval + logl(Y[i]));
	}
	root->propogate();
	return root-> val;
	
}
int updateX(int pos, int val)
{
	root->update(pos, n-1, (inv(x[pos])*(val%mod))%mod, logl(val)-logl(x[pos]));
	x[pos] = val;
	root->propogate();
	return root->val;
}
int updateY(int pos, int val)
{
	root->update(pos, pos, (inv(y[pos])*(val%mod))%mod, logl(val)-logl(y[pos]));
	y[pos]= val;
	root->propogate();
	return root->val;
}

Compilation message

horses.cpp: In function 'int init(int, int*, int*)':
horses.cpp:110:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  110 |   root->update(i, i, (val*(Y[i]%mod))%mod, logval + logl(Y[i]));
      |                ^
horses.cpp:110:19: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  110 |   root->update(i, i, (val*(Y[i]%mod))%mod, logval + logl(Y[i]));
      |                   ^
horses.cpp:113:16: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  113 |  return root-> val;
      |         ~~~~~~~^~~
horses.cpp: In function 'int updateX(int, int)':
horses.cpp:118:21: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  118 |  root->update(pos, n-1, (inv(x[pos])*(val%mod))%mod, logl(val)-logl(x[pos]));
      |                    ~^~
horses.cpp:121:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  121 |  return root->val;
      |         ~~~~~~^~~
horses.cpp: In function 'int updateY(int, int)':
horses.cpp:128:15: warning: conversion from 'll' {aka 'long long int'} to 'int' may change value [-Wconversion]
  128 |  return root->val;
      |         ~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 424 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 1 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 344 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 344 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 436 KB Output is correct
20 Correct 0 ms 344 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 2 ms 668 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 600 KB Output is correct
27 Correct 1 ms 600 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 315 ms 106892 KB Output is correct
2 Correct 509 ms 119892 KB Output is correct
3 Correct 477 ms 110672 KB Output is correct
4 Correct 545 ms 114512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 436 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 0 ms 436 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 2 ms 452 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 604 KB Output is correct
28 Correct 1 ms 604 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 2 ms 604 KB Output is correct
31 Correct 1 ms 604 KB Output is correct
32 Correct 1 ms 604 KB Output is correct
33 Correct 262 ms 109876 KB Output is correct
34 Correct 269 ms 110040 KB Output is correct
35 Correct 260 ms 116980 KB Output is correct
36 Correct 286 ms 116908 KB Output is correct
37 Correct 237 ms 108116 KB Output is correct
38 Correct 265 ms 109112 KB Output is correct
39 Correct 229 ms 108164 KB Output is correct
40 Correct 266 ms 111972 KB Output is correct
41 Correct 227 ms 108372 KB Output is correct
42 Correct 228 ms 108116 KB Output is correct
43 Correct 252 ms 112372 KB Output is correct
44 Correct 265 ms 112468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 344 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 436 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 344 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 692 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 0 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 604 KB Output is correct
24 Correct 2 ms 600 KB Output is correct
25 Correct 1 ms 604 KB Output is correct
26 Correct 1 ms 604 KB Output is correct
27 Correct 1 ms 592 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 604 KB Output is correct
30 Correct 2 ms 448 KB Output is correct
31 Correct 1 ms 600 KB Output is correct
32 Correct 1 ms 448 KB Output is correct
33 Correct 320 ms 110856 KB Output is correct
34 Correct 504 ms 119448 KB Output is correct
35 Correct 478 ms 111060 KB Output is correct
36 Correct 517 ms 114652 KB Output is correct
37 Correct 265 ms 109908 KB Output is correct
38 Correct 263 ms 109904 KB Output is correct
39 Correct 265 ms 116816 KB Output is correct
40 Correct 268 ms 117108 KB Output is correct
41 Correct 265 ms 108208 KB Output is correct
42 Correct 263 ms 109116 KB Output is correct
43 Correct 236 ms 108160 KB Output is correct
44 Correct 268 ms 111908 KB Output is correct
45 Correct 234 ms 108148 KB Output is correct
46 Correct 233 ms 108116 KB Output is correct
47 Correct 311 ms 112468 KB Output is correct
48 Correct 265 ms 112352 KB Output is correct
49 Correct 480 ms 112040 KB Output is correct
50 Correct 492 ms 112104 KB Output is correct
51 Correct 309 ms 118924 KB Output is correct
52 Correct 341 ms 118636 KB Output is correct
53 Correct 418 ms 110484 KB Output is correct
54 Correct 366 ms 110868 KB Output is correct
55 Correct 333 ms 109140 KB Output is correct
56 Correct 409 ms 113896 KB Output is correct
57 Correct 281 ms 109652 KB Output is correct
58 Correct 305 ms 110380 KB Output is correct
59 Correct 257 ms 112476 KB Output is correct