Home Web Front-end HTML Tutorial CF Question Collection PART 7 #264 div 2 E_html/css_WEB-ITnose

CF Question Collection PART 7 #264 div 2 E_html/css_WEB-ITnose

Jun 24, 2016 am 11:57 AM
cf div

【原题】

E. Caisa and Tree

time limit per test

10 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Caisa is now at home and his son has a simple task for him.

Given a rooted tree with n vertices, numbered from 1 to n (vertex 1 is the root). Each vertex of the tree has a value. You should answer q queries. Each query is one of the following:

  • Format of the query is "1 v". Let's write out the sequence of vertices along the path from the root to vertex v: u1,?u2,?...,?uk (u1?=?1; uk?=?v). You need to output such a vertex ui that gcd(value of ui,?value of v)?>?1 and i?
  • Format of the query is "2 v w". You must change the value of vertex v to w.
  • You are given all the queries, help Caisa to solve the problem.

    Input

    The first line contains two space-separated integers n, q (1?≤?n,?q?≤?105).

    The second line contains n integers a1,?a2,?...,?an (1?≤?ai?≤?2·106), where ai represent the value of node i.

    Each of the next n?-?1 lines contains two integers xi and yi (1?≤?xi,?yi?≤?n; xi?≠?yi), denoting the edge of the tree between vertices xi and yi.

    Each of the next q lines contains a query in the format that is given above. For each query the following inequalities hold: 1?≤?v?≤?n and 1?≤?w?≤?2·106. Note that: there are no more than 50 queries that changes the value of a vertex.

    Output

    For each query of the first type output the result of the query.

    Sample test(s)

    input

    4 610 8 4 31 22 33 41 11 21 31 42 1 91 4
    Copy after login

    output

    -112-11
    Copy after login

    Note

    gcd(x,?y) is greatest common divisor of two integers x and y.


    【分析】这道题是做现场赛的。本来能A的,但是太紧张了=而且也不会用vector,边表搞的麻烦死了。

    开始看到修改操作才50次、时间又松,真是爽!估计每次可以暴力重构这颗树,然后对于每个质因子记录最优值。

    首先每次不能sqrt的效率枚举一个数的因子,我们可以预处理出每个数的所有质因子。(其实有更省空间的)

    剩下来要解决的问题是:因为我是用dfs的,怎么把某个子树的信息在搜完后再去掉?(以免影响其他子树)HHD表示用vector一点也不虚。其实应该也可以用边表类似的思路,但是麻烦= =

    【代码】

    #include#include#include#include#define N 100005#define S 2000005#define push push_back#define pop pop_backusing namespace std;vectorfac[S],f[S];int data[N],ans[N],end[N],pf[S],deep[N];int C,cnt,n,Q,i,x,y,opt;struct arr{int go,next;}a[N*2];inline void add(int u,int v){a[++cnt].go=v;a[cnt].next=end[u];end[u]=cnt;}inline void init(){  int H=2000000;  for (int i=2;i<=H;i++)    if (!pf[i])    {      for (int j=i;j<=H;j+=i)        fac[j].push(i),pf[j]=1;    }}void dfs(int k,int fa){  int P=data[k];  for (int i=0;ideep[ans[k]]) ans[k]=f[go][temp-1];    f[go].push(k);  }  for (int i=end[k];i;i=a[i].next)    if (a[i].go!=fa)      dfs(a[i].go,k);  for (int i=0;i

    Statement of this Website
    The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

    Hot AI Tools

    Undresser.AI Undress

    Undresser.AI Undress

    AI-powered app for creating realistic nude photos

    AI Clothes Remover

    AI Clothes Remover

    Online AI tool for removing clothes from photos.

    Undress AI Tool

    Undress AI Tool

    Undress images for free

    Clothoff.io

    Clothoff.io

    AI clothes remover

    AI Hentai Generator

    AI Hentai Generator

    Generate AI Hentai for free.

    Hot Article

    R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
    2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. Best Graphic Settings
    2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
    R.E.P.O. How to Fix Audio if You Can't Hear Anyone
    2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

    Hot Tools

    Notepad++7.3.1

    Notepad++7.3.1

    Easy-to-use and free code editor

    SublimeText3 Chinese version

    SublimeText3 Chinese version

    Chinese version, very easy to use

    Zend Studio 13.0.1

    Zend Studio 13.0.1

    Powerful PHP integrated development environment

    Dreamweaver CS6

    Dreamweaver CS6

    Visual web development tools

    SublimeText3 Mac version

    SublimeText3 Mac version

    God-level code editing software (SublimeText3)

    How to set up cf Logitech one-click macro? cf logitech mouse macro settings How to set up cf Logitech one-click macro? cf logitech mouse macro settings Mar 14, 2024 pm 10:50 PM

    Mouse macros assign a series of complex operations to the mouse buttons, which can be simply understood as mouse shortcut key settings. After clicking the button to set the mouse macro, you can complete some operations that are usually impossible to do. So how to set mouse macros when playing CF? Let’s take a look at the cf Logitech mouse macro setting tutorial. 1. First, install the Logitech game software on your computer, and then click as shown by the arrow in the picture to open the custom button setting interface. Next, you need to select a key, such as the left key, click the small arrow, and then select "Edit Command" in the pop-up menu, so that you can open the left key macro setting interface. 3. Then click the button, as shown by the red arrow in the picture, click the text box and enter any key. Note that such as A

    How to use css to realize that a div is missing a corner How to use css to realize that a div is missing a corner Jan 30, 2023 am 09:23 AM

    CSS method to realize that a div is missing a corner: 1. Create an HTML sample file and define a div; 2. Set the width and height background color for the div; 3. Add a pseudo class to the div that needs to delete a corner, and set the pseudo class to Use the same color as the background color, then rotate it 45 degrees, and then position it to the corner that needs to be removed.

    Implementation of word-marking translation browser script based on ChatGPT API Implementation of word-marking translation browser script based on ChatGPT API May 01, 2023 pm 03:28 PM

    Preface Recently, there is a browser script based on ChatGPTAPI on GitHub, openai-translator. In a short period of time, the star has reached 12k. In addition to supporting translation, it also supports polishing and summarizing functions. In addition to browser plug-ins, it also uses tauri packaging. If you have a desktop client, aside from the fact that tauri uses the rust part, the browser part is still relatively simple to implement. Today we will implement it manually. The interface provided by openAI, for example, we can copy the following code and initiate a request in the browser console to complete the translation //Example constOPENAI_API_KEY="s

    What is the div box model What is the div box model Oct 09, 2023 pm 05:15 PM

    The div box model is a model used for web page layout. It treats elements in a web page as rectangular boxes. This model contains four parts: content area, padding, border and margin. The advantage of the div box model is that it can easily control the layout of the web page and the spacing between elements. By adjusting the size of the content area, inner margin, border and outer margin, various layout effects can be achieved. The box model also provides some Properties and methods can dynamically change the style and behavior of the box through CSS and JavaScript.

    What are the differences between div and span? What are the differences between div and span? Nov 02, 2023 pm 02:29 PM

    The differences are: 1. div is a block-level element, and span is an inline element; 2. div will automatically occupy a line, while span will not automatically wrap; 3. div is used to wrap larger structures and layouts, and span is used to wrap Text or other inline elements; 4. div can contain other block-level elements and inline elements, and span can contain other inline elements.

    What is the difference between iframe and div What is the difference between iframe and div Aug 28, 2023 am 11:46 AM

    The difference between iframe and div is that iframe is mainly used to introduce external content, which can load content from other websites or divide a web page into multiple areas. Each area has its own independent browsing context, while div is mainly used to divide and organize content. block for layout and style control.

    How to adjust the smoke head in WIN10 system cf How to adjust the smoke head in WIN10 system cf Feb 26, 2024 pm 04:17 PM

    Adjustment steps: 1. On the Win10 system desktop, right-click the start button and select "Settings"; 2. Click the "System" icon; 3. Click the "Display" menu item in the left sidebar; 4. Click "Display Adapter" on the right Properties" shortcut link; 5. Click the "List all modes" button; 6. Select "1024*768 True Color 60 Hz" from all modes; 7. Click the "Monitor" label above and set it to 60 Hz; 8. Click "OK" and then restart the computer.

    How to display two divs side by side How to display two divs side by side Nov 01, 2023 am 11:36 AM

    The methods are: 1. Set the two div elements to the "float:left;" attribute; 2. Use CSS's flex layout to easily display elements side by side; 3. Use CSS's grid layout to also display elements side by side.

    See all articles