답안 #593410

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
593410 2022-07-11T06:07:00 Z saayan007 Simple game (IZhO17_game) C++14
0 / 100
9 ms 15956 KB
#include <bits/stdc++.h>
using namespace std;

/* higher types */
typedef long long ll;
typedef long double ld;

/* pairs */
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<double, double> pd;
typedef pair<ld, ld> pld;

/* vectors */
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<ld> vld;
typedef vector<string> vs;
typedef vector<bool> vb;

typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<pd> vpd;
typedef vector<pld> vpld;

/* 2d vectors */
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vd> vvd;
typedef vector<vld> vvld;
typedef vector<vs> vvs;
typedef vector<vb> vvb;

/* initialisation */
#define initvvi(mat, n, x) for(auto u : mat) u = vi(n, x);
#define initvvl(mat, n, x) for(auto u : mat) u = vl(n, x);
#define initvvb(mat, n, x) for(auto u : mat) u = vb(n, x);
#define initvvd(mat, n, x) for(auto u : mat) u = vd(n, x);
#define initvvs(mat, n, x) for(auto u : mat) u = vs(n, x);

/* loops */
#define fur(i, a, b) for(ll i = a; i <= (ll)b; ++i)
#define ruf(i, a, b) for(ll i = a; i >= (ll)b; --i)
#define each(u, v) for(auto u : v )

/* input */
#define rv(v) for(auto &u : v) cin >> u;
#define rm(mat, m) for(ll j = 0; j <= (ll)(m-1)) for(auto u : mat[j]) cin >> u;

/* output */
#define pv(v) for(auto x : v) cout << x << ' '; cout << nl;
#define pm(m) for(auto n : m) pv(n);

/* shortforms */
#define fr first 
#define sc second
#define pb push_back

#define nl "\n"
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

/* constants */
const ll infl = numeric_limits<long long int>::max();
const int infi = numeric_limits<int>::max();
const int modi = 1e9 + 7;
const ll modl = 1e9 + 7;

int n, m;
vi y;
vi seg;

void add(int increment, int node)
{
    node += 2000000;
    seg[node] += increment;
    for(node /= 2; node >= 1; node /= 2)
        seg[node] = seg[2*node] + seg[2*node+1];
}

int sum(int a, int b)
{
    a += 2000000;
    b += 2000000;
    int s = 0;
    while(a <= b)
    {
        if(a%2 == 1) s+= seg[a++];
        if(b%2 == 0) s+= seg[b++];
        a /= 2;
        b /= 2;
    }
    return s;
}

void remove_line(int a, int b)
{
    if(a > b)
        swap(a, b);
    add(-1, a + 1);
    add(1, b);
}

void add_line(int a, int b)
{
    if(a > b)
        swap(a, b);
    add(1, a + 1);
    add(-1, b);
}

void solve()
{
    cin >> n >> m;
    y.resize(n + 1);
    seg.resize(4000000 + 2, 0);

    cin >> y[1];
    fur(i, 2, n)
    {
        cin >> y[i];
        add_line(y[i], y[i-1]);
    }

    while(m--)
    {
        int type;
        cin >> type;
        if(type == 2)
        {
            int h;
            cin >> h;
            cout << sum(1, h) << nl;
            continue;
        }
        
        int i, h;
        cin >> i >> h;
        if(i != 1)
        {
            remove_line(y[i], y[i-1]);
            add_line(h, y[i-1]);
        }
        if(i != n)
        {
            remove_line(y[i], y[i+1]);
            add_line(h, y[i+1]);
        }
        y[i] = h;
    }
}

int main() 
{
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
    
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

	ll t = 1;
    /* cin >> t; */
    while(t--)
    {
        solve();
    }
}

Compilation message

game.cpp: In function 'int main()':
game.cpp:157:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  157 |         freopen("input.txt","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
game.cpp:158:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  158 |         freopen("output.txt","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 9 ms 15956 KB Output isn't correct
2 Halted 0 ms 0 KB -